R
Rosemary
I can't seem to generate a Word document from a template. It's Office 2007.
Below is a subset of the code:
Private Sub PrintToWord(bfor As Boolean)
Dim iControlNumber As Integer
Dim sDocName As String
Dim txtDocName As String
Dim iReturnVal As Integer
Dim doc As Word.Application
Dim oDoc As Word.Document
If bfor = True Then
sDocName = "Validation Memo.dotm"
End If
'Check if the document exists
Set fso = CreateObject("Scripting.FileSystemObject")
txtDocName = Application.CurrentProject.Path & "\Memos\" & sName & " " &
iControlNumber & " Foreign Representative Validation Memo.docx"
If fso.FileExists(txtDocName) = True Then
.....
Else 'create the document and display
' Set the variable (runs new instance of Word.)
Set doc = CreateObject("Word.Application")
Set oDoc = doc.Documents.Add(Application.CurrentProject.Path &
"\Templates\" & sDocName)
'Save the document
oDoc.SaveAs txtDocName
oDoc.Close
doc.NormalTemplate.Saved = True
doc.Quit
Set oDoc = Nothing
Set doc = Nothing
End If
Can anyone help with this?
Thanks
Below is a subset of the code:
Private Sub PrintToWord(bfor As Boolean)
Dim iControlNumber As Integer
Dim sDocName As String
Dim txtDocName As String
Dim iReturnVal As Integer
Dim doc As Word.Application
Dim oDoc As Word.Document
If bfor = True Then
sDocName = "Validation Memo.dotm"
End If
'Check if the document exists
Set fso = CreateObject("Scripting.FileSystemObject")
txtDocName = Application.CurrentProject.Path & "\Memos\" & sName & " " &
iControlNumber & " Foreign Representative Validation Memo.docx"
If fso.FileExists(txtDocName) = True Then
.....
Else 'create the document and display
' Set the variable (runs new instance of Word.)
Set doc = CreateObject("Word.Application")
Set oDoc = doc.Documents.Add(Application.CurrentProject.Path &
"\Templates\" & sDocName)
'Save the document
oDoc.SaveAs txtDocName
oDoc.Close
doc.NormalTemplate.Saved = True
doc.Quit
Set oDoc = Nothing
Set doc = Nothing
End If
Can anyone help with this?
Thanks