Hello:
I've been using an Access form with a textbox to open a Word template. The idea was to have the user type in a value into the text box and then have that value replace the text at a pre-existing bookmark already set in the template file ahead of time...
Here is a code sample. At the moment, I can get the Word document template file to open, but when I get to selecting the bookmark it doesn't recognize my code as a valid command/function.
Any ideas/suggestions most appreciated...
Thanks,
marcus101
Access/SQL/XML Developer
Ottawa, Canada
I've been using an Access form with a textbox to open a Word template. The idea was to have the user type in a value into the text box and then have that value replace the text at a pre-existing bookmark already set in the template file ahead of time...
Here is a code sample. At the moment, I can get the Word document template file to open, but when I get to selecting the bookmark it doesn't recognize my code as a valid command/function.
Code:
Dim sigVal as String
Dim tempDoc as String
sigVal = Me.theSig.Value
tempDoc = "C:\Templates\temp1.dot"
Dim objWordDoc As Object
Set objWordDoc = GetObject(tempDoc, "Word.Document")
'Dim WordApp As Word.Application
'Dim WordDoc As Word.Document
'Set WordApp = CreateObject("Word.Application")
'Set WordDoc = WordApp.Documents.Open(tempDoc)
objWordDoc.Application.Visible = True
' Code to jump to Bookmark Selection then replace?
If Not IsNull(sigVal) Then
' NOTE: This line below is where the code fails...
objWordDoc.Selection.GoTo wdGoToBookmark, , , "AgentSig"
' objWordDoc.Selection.Find.ClearFormatting ' needed?
' TEST: Is this entire section needed?
'With objWordDoc.Selection.Find
' .Text = ""
' .Replacement.Text = ""
' .Forward = True
' .Wrap = wdFindContinue
' .Format = False
' .MatchCase = False
' .MatchWholeWord = False
' .MatchWildcards = False
' .MatchSoundsLike = False
' .MatchAllWordForms = False
'End With
objWordDoc.Selection.TypeText Text:=sigVal
objWordDoc.Save
End If
objWordDoc.Close SaveChanges:=-1 '-1 = wdSaveChanges
Set objWordDoc = Nothing
Any ideas/suggestions most appreciated...
Thanks,
marcus101
Access/SQL/XML Developer
Ottawa, Canada