Hi there
I have the strangest problem! I have a form builder that opens a word template and populates the letter based on the values in the form, then saves the .dotx template as a .doc file. It works fine unless I go back to the form builder and make a change and request the program to run again. Then the program modifies the Any help is appreciated! This was a last minute find and the program is being presented to the vp on Tuesday! My word code is below:
I can't figure out why if the program is generated more than once while the docs are open with no variable change the template would be changed. Any help is soooo greatly appreciated!
I have the strangest problem! I have a form builder that opens a word template and populates the letter based on the values in the form, then saves the .dotx template as a .doc file. It works fine unless I go back to the form builder and make a change and request the program to run again. Then the program modifies the Any help is appreciated! This was a last minute find and the program is being presented to the vp on Tuesday! My word code is below:
Code:
public Sub Insert_Bm_Text()
Dim WDApp As Word.Application
Dim WDDoc As Word.Document
Dim wdbm As Word.Bookmark
Dim path As String
Dim template As String
Dim tmp As String
template = "hletemplate.dotx"
Set WDApp = New Word.Application
'reference path'
path = ActiveWorkbook.path
'Reference active document'
Dim BMRange As Range
Dim wordapp As Object
Dim wrdDoc As Object
Dim tmpDoc As Object
Set wordapp = GetObject(, "Word.Application")
If wordapp Is Nothing Then
'no current word application
Set wordapp = CreateObject("Word.Application")
Set WDDoc = Word.Documents.Open(path & "\" & template)
wordapp.Visible = True
Else:
'word app running
Set WDDoc = Word.Documents.Open(path & "\" & template)
WDApp.Visible = True
End If
'loop -on error continue
On Error Resume Next
The program then fills in the fields and then the following code saves the doc and notifies the user
'save as'
path = path & "\" & Txtclient & "_" & txtcr_no & "HLE.doc"
WDDoc.SaveAs (path)
'save document and close word'
'WDDoc.Save
WDDoc.Close
WDApp.Quit False
Set WDApp = Nothing
AppActivate "Microsoft Excel"
MsgBox (path & " has been created. Click OK to view")
tmp = "explorer.exe """ & path & """"
Shell tmp, vbNormalFocus
Last edited by a moderator: