Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sending XL Data to Word Bookmark

Status
Not open for further replies.

nickadeemus2002

Programmer
Feb 27, 2004
9
US
Hello all. Good afternoon.

I need help with the following problem. I am truing to send the used range of a worksheet into a MS Word Bookmark. I can't get it to work. Here's what I have so far:
Public Sub SendToWord()
Dim CAP As Range
Set CAP = Sheets("InitialAssessments").UsedRange.Select
CAP.Copy
Set myWord = CreateObject("Word.Application")
With myWord
.Visible = True
.Documents.Open Filename:= _
"C:\Documents and Settings\chrisv\Desktop\HBC2\ Report Document.doc", _
ReadOnly:=True
.ActiveDocument.Bookmarks("InitialAssessments").Select
With Selection
.Paste CAP
End With
End With
End Sub


Any suggestions??

All help is appreciated
 
Hi,

What's not working? On what statement is it burping?

Skip,

Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Thanks for the quick response Skip. When I go through the code using F8, I get a Runtime Error 424, Object required when these lines are executed

Set CAP = Sheets("InitialAssessments").UsedRange.Select
CAP.Copy

I can't figure out why.

Appreciate the help.
 
Loose the Select
Code:
Set CAP = Sheets("InitialAssessments").UsedRange


Skip,

Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Thanks Skip. That work well.

Now I am getting a Runtime Error 5174: Application defined or object defined error.

When I step through the code, the Word APP starts (the window opens without a document, so I successfully created an instance), but it won't load my document. I triple checked the filepath and it is correct. Am I missing some syntax arguments?

 
I think that you might need to use GetObject rather than CreateObject. Check HELP for checking for a running instance of Word and registering the instance you may then start.

Skip,

Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Okay, I figured out how to get the word document up and going. I can get all the way down to the bookmark that is within the document. My problem is I don't know which method in Word VBA will allow me to copy the usedrange from excel into the document. Suggestions?

Here's the code:

Public Sub SendToWord()
Dim CAP As Range
Dim myWord As Word.Application
Set CAP = Sheets("InitialAssessments").UsedRange
CAP.Copy
Set myWord = New Word.Application
With myWord
.Visible = True
.Activate
myWord.Documents.Open _
Filename:="C:\Documents and Settings\chrisv\Desktop\HBC2\Report Document\HBC Reporting Document.doc"
With Selection
myWord.ActiveDocument.Bookmarks("InitialAssessments").Select

<<How do I copy the range here?>>
End With
End With
End Sub
 
Use the Paste Method

Skip,

Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top