-
Okay I open the Word doc actually dot that I need. Now I need to with code print text with variables in between; any ideas?
Should I use a bookmark; start at the beginning of the doc and have the code print the info? But how would the code in VB look to do this; any examples would be great!
Thanks
-
I think this is what you are looking for:
Dim WordApp As Word.Application
'Starting Word
Set WordApp = New Word.Application
DoEvents
'Open template
WordApp.Documents.Open "Template path and name.dot"
If Err = 0 Then
'Attaching data source
WordApp.ActiveDocument.MailMerge.OpenDataSource "Data path and name"
If Err = 0 Then
'Run the mail merge
WordApp.ActiveDocument.MailMerge.Execute
'Save the document
If Err = 0 Then
WordApp.ActiveDocument.SaveAs "Save path and filename.doc", wdFormatDocument
If Err = 0 Then
'Close all open Word documents and exit Word
WordApp.Documents.Close wdDoNotSaveChanges
WordApp.Application.Quit
Set WordApp = Nothing
-
I dont need to do a word merge, I would just like to insert default text into the document that is stringed to variables from the program. The merge would be slower and more complicated for what I need.
Thanks
-
here is the magical code once i open the active document i do this code to insert variables and text!!!
obj.Selection.TypeText Date ' Insert current date