Can anyone tell me how to paste a cell into open word doc

drrchrds

New Member
Joined
Oct 26, 2010
Messages
13
I need to do something that seems like it should be fairly simple:
I want a macro to paste a single cell from excel to the end of whatever word doc I happen to have open at the time. After pasting, I want to come back to the excel doc. I will have the word doc open on the left and my spreadsheet open on the right. I use Office 2007. Thanks if you can help!
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.

poolhall

Active Member
Joined
Jan 9, 2009
Messages
350
try:

Code:
Sub PasteToWord()
    Dim AppWord As Word.Application
     
    On Error Resume Next

    Set AppWord = GetObject(, "Word.Application")
    
    If Err.Number <> 0 Then
        Set AppWord = CreateObject("Word.Application")
        AppWord.Documents.Add
     End If
    
    AppWord.Visible = True
    Sheet1.Range("A1").Copy
    AppWord.Selection.Paste
     
    Application.CutCopyMode = False

    Set AppWord = Nothing
End Sub
It will paste the content of Sheet1!A1 at the cursor position in an open Word doc; if no open Word document exist, it will create a new one.
 

drrchrds

New Member
Joined
Oct 26, 2010
Messages
13
Poolhall, thank you for the response.
I am getting an error:
"User-defined type not defined"
Is there something I can do to fix that?

BTW: Ideally, I would like it to "paste special" (as unformatted text) to the end of the word doc (as if in word I were to type: CTRL-END, then click on "Paste Special", Unformatted text). I don't want it to paste as a table, but rather just the value of the cell.
 

poolhall

Active Member
Joined
Jan 9, 2009
Messages
350
oops, sorry, forgot to mention that you need a reference to 'Microsoft Word 12 Object Library' or 'Microsoft Word 10.0' for prior Word versions. In VBA Editor, go to menu Tools - References and choose it there.
 

drrchrds

New Member
Joined
Oct 26, 2010
Messages
13
Poolhall,
AWESOME! It worked after I tweaked a bit. Here is what I have now:

Code:
Sub PasteToWord()
    'Dim AppWord As Word.Application
     
    On Error Resume Next

    Set AppWord = GetObject(, "Word.Application")
    
    If Err.Number <> 0 Then
        Set AppWord = CreateObject("Word.Application")
        AppWord.Documents.Add
     End If
    
    AppWord.Visible = True
    Sheet1.Range("A1").Copy
    AppWord.Selection.PasteAndFormat (wdPasteDefault)
    AppWord.Selection.TypeBackspace
     
    Application.CutCopyMode = False

    Set AppWord = Nothing
End Sub
Oddly, once I killed the first line it no longer gave me an error msg.
The tweak at the end was just my guess based on code I copied out of a word macro. The "backspace" just gets rid of the paragraph that is otherwise inserted after the paste. It is working exactly how I hoped! I can't thank you enough, this is about to become a great productivity enhancer for me!
:):):)
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,151,981
Messages
5,767,435
Members
425,413
Latest member
ccfam04

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top