Inserting File into Word - Setting Selection

Nwalach

Registered User.
Local time
Today, 11:47
Joined
Jun 2, 2003
Messages
12
Hi,

Well, I've hit another roadblock.

I need to, from access, insert a file into an already open word document after a certain line of text. I am new to VBA and I simply don't know how to tell word where I want this document inserted. I know I should use the select method, but I am not sure what the syntax would be.

This is what I have so far:

Private Sub Command32_Click()
On Error GoTo Err_Command32_Click

Dim DocName As String
Dim WordObj As Object
Dim RptWhere As String
Dim rtp As Report
Dim SourceName As String

SourceName = "HMC" & Me.ID & ".doc"
RptWhere = "[ID] = " & Me.ID
DocName = "Article: Single Attributes"
DoCmd.OpenReport DocName, acViewPreview, , RptWhere
DoCmd.OutputTo acOutputReport, DocName, acFormatRTF, "Template.doc", True


Set WordObj = GetObject("Template.doc", "Word.Basic")


WordObj.Selection.InsertFile (SourceName)


Exit_Command32_Click:
Exit Sub

Err_Command32_Click:
MsgBox Err.Description
Resume Exit_Command32_Click

End Sub

Thank you so much for your time.

Nick
 
Insert a bookmark in the word document called "InsertHere", then try

With objWord.ActiveDocument.Bookmarks("InsertHere").Select

before you insert the file
 
Yeah, I had thought about doing it, but I was trying to create the entire document from scratch from within Access. I ended up putting a long string of gobbly-gook into what was being exported to Word and then using

WordObj.Selection.Find.Execute FindText:="@$#@$#***&", Forward:=True
WordObj.Selection.InsertFile (SourceName)

to replace the gibberish with my file.

This project has been very educational but a little frustrating and this forum has been continually saving my neck.

Thank you.
 

Users who are viewing this thread

Back
Top Bottom