Hi
I have an Access2003 database I use to open a MS Word template (its a form users will complete when sent out)and fill in certain bookmarked areas with info from a query. - works great. However, I also need to edit the header and footer (same on all pages) with some of the data as well, but I cannot figure out how to do it.
My code is below. Any ideas would really help - seems like it should be something simple - been working all day on this with no luck.
Thanks
Dim oApp As Object 'Variable for Word
Dim sFilename As String 'Variable for Auto-Save file name
Dim strTemplateName As String 'Variable for Word Template to be used
Dim objWORDdoc As Object
strTemplateName = "C:\Documents and Settings\folderx \MASTERTEMPLATE_auto2.dot"
sFilename = "C:\Documents and Settings\folderx\SAW_SummaryTemplate_v0309ra_BCS" & vBCS & "_H2.doc"
Set oApp = CreateObject("Word.Application")
oApp.Visible = True
If Dir(sFilename) = "" Then 'Test to see if created filename already exists
'and if not, open Template to fill in date
Set oApp = CreateObject("Word.Basic") 'otherwise just open that filename already
With oApp
.filenew Template:=strTemplateName
.EditBookmark Name:="TextVBA2", GoTo:=True
.Insert vSubCat
.filesaveas Name:=sFilename
End With
Else 'If filename already exists, just open the file at this point
oApp.Documents.Open sFilename
oApp.ActiveDocument.Save
End If
Dim oHF As HeaderFooter
Dim var
Dim HeaderText
Dim FooterText
HeaderText = vSomeRecordSpecificID 'been texting with simple "string"
FooterText = vFilename 'been texting with simple "string"
'BLOWS UP HERE:
oApp.Documents.Open.Sections.Headers.Range.Delete
oApp.Documents.Open.Sections.Headers.Range.Text = HeaderText
oApp.ActiveDocument.Save
I have an Access2003 database I use to open a MS Word template (its a form users will complete when sent out)and fill in certain bookmarked areas with info from a query. - works great. However, I also need to edit the header and footer (same on all pages) with some of the data as well, but I cannot figure out how to do it.
My code is below. Any ideas would really help - seems like it should be something simple - been working all day on this with no luck.
Thanks
Dim oApp As Object 'Variable for Word
Dim sFilename As String 'Variable for Auto-Save file name
Dim strTemplateName As String 'Variable for Word Template to be used
Dim objWORDdoc As Object
strTemplateName = "C:\Documents and Settings\folderx \MASTERTEMPLATE_auto2.dot"
sFilename = "C:\Documents and Settings\folderx\SAW_SummaryTemplate_v0309ra_BCS" & vBCS & "_H2.doc"
Set oApp = CreateObject("Word.Application")
oApp.Visible = True
If Dir(sFilename) = "" Then 'Test to see if created filename already exists
'and if not, open Template to fill in date
Set oApp = CreateObject("Word.Basic") 'otherwise just open that filename already
With oApp
.filenew Template:=strTemplateName
.EditBookmark Name:="TextVBA2", GoTo:=True
.Insert vSubCat
.filesaveas Name:=sFilename
End With
Else 'If filename already exists, just open the file at this point
oApp.Documents.Open sFilename
oApp.ActiveDocument.Save
End If
Dim oHF As HeaderFooter
Dim var
Dim HeaderText
Dim FooterText
HeaderText = vSomeRecordSpecificID 'been texting with simple "string"
FooterText = vFilename 'been texting with simple "string"
'BLOWS UP HERE:
oApp.Documents.Open.Sections.Headers.Range.Delete
oApp.Documents.Open.Sections.Headers.Range.Text = HeaderText
oApp.ActiveDocument.Save