Hello,
I have a form with a VBA code that export data to a MS Word template. After exporting I would like to give the user two options:
1) Open the MS Word document
2) Only print the document without opening it
I am having problems with the second option as it always opens the document and get the save as window. Could it be because it's a template? Thank you
I have a form with a VBA code that export data to a MS Word template. After exporting I would like to give the user two options:
1) Open the MS Word document
2) Only print the document without opening it
I am having problems with the second option as it always opens the document and get the save as window. Could it be because it's a template? Thank you
Code:
Private Sub cmdExportToWord_Click()
' Code to export and save data to MS Word Template
On Error Resume Next
Dim objWord As Object
Dim strPath As String
Dim AnswerYes As String
Dim AnswerNo As String
strPath = "C:\templates\mytemplate.dot"
Set objWord = CreateObject("Word.Application")
objWord.Visible = False
objWord.Documents.Add strPath
objWord.ActiveDocument.bookmarks("YEAR").Select
objWord.Selection.Text = Me.YEAR
objWord.ActiveDocument.bookmarks("FNAME").Select
objWord.Selection.Text = Me.txtFNAME
objWord.ActiveDocument.bookmarks("LNAME").Select
objWord.Selection.Text = Me.txtLNAME
AnswerYes = MsgBox("Click YES to Open and modify the Word Template or NO to Print", vbQuestion + vbYesNo, "Templates")
If AnswerYes = vbYes Then
objWord.Visible = True
Else
objWord.Visible = False
objWord.PrintOut
objWord.Quit
End If
End Sub