R
Rodger
Hello all,
I am trying to create a mail merge. The data is in a csv file and the
Word Document is a Template.
Here is part of my code
'CREATE WORD DOCUMENTS
myTemplatePath = "R:\Application Documents"
myTemplateName = myTemplatePath & "\504 CDC Checklist for
Submitting loan.dot"
'504 CDC Checklist for Submitting loan
myDocName = myDocumentPath & "\" & myFolderName & "\504 CDC
Checklist for Submitting loan.doc"
myDataSource = myDocumentPath & "\" & myFolderName &
"\tmp_CheckLists.csv"
Set oApp = GetObject(myTemplateName, "Word.Document")
'oApp.Application.Visible = True
oApp.MailMerge.OpenDataSource Name:=myDataSource,
LinktoSource:=True, AddToRecentFiles:=False
oApp.MailMerge.Destination = wdSendToNewDocument
oApp.MailMerge.SuppressBlankLines = True
oApp.MailMerge.Execute
oApp.Application.Documents(1).SaveAs (myDocName)
If myView = 2 Then
oApp.Application.Visible = True
oApp.Close SaveChanges:=wdDoSaveChanges
Else
oApp.Application.ActiveDocument.PrintOut
oApp.Application.Documents(1).Close
End If
Set oApp = Nothing
OK here is the issue.
If I run the code twice I still have WINWORD.exe open. I need to be
able to run this from multiple PCs. I thought that I had this working
but it seems that I don't
I am sure I am missing somthing simple.
The csv file if being created and the Word Template is there. When I
run the code for the first time all works great but then if I want to
print the document I get an error that the file is open. Only because
it never close properly. How can I make sure that WINWORD.EXE is
closed?
TIA,
Rodger
I am trying to create a mail merge. The data is in a csv file and the
Word Document is a Template.
Here is part of my code
'CREATE WORD DOCUMENTS
myTemplatePath = "R:\Application Documents"
myTemplateName = myTemplatePath & "\504 CDC Checklist for
Submitting loan.dot"
'504 CDC Checklist for Submitting loan
myDocName = myDocumentPath & "\" & myFolderName & "\504 CDC
Checklist for Submitting loan.doc"
myDataSource = myDocumentPath & "\" & myFolderName &
"\tmp_CheckLists.csv"
Set oApp = GetObject(myTemplateName, "Word.Document")
'oApp.Application.Visible = True
oApp.MailMerge.OpenDataSource Name:=myDataSource,
LinktoSource:=True, AddToRecentFiles:=False
oApp.MailMerge.Destination = wdSendToNewDocument
oApp.MailMerge.SuppressBlankLines = True
oApp.MailMerge.Execute
oApp.Application.Documents(1).SaveAs (myDocName)
If myView = 2 Then
oApp.Application.Visible = True
oApp.Close SaveChanges:=wdDoSaveChanges
Else
oApp.Application.ActiveDocument.PrintOut
oApp.Application.Documents(1).Close
End If
Set oApp = Nothing
OK here is the issue.
If I run the code twice I still have WINWORD.exe open. I need to be
able to run this from multiple PCs. I thought that I had this working
but it seems that I don't
I am sure I am missing somthing simple.
The csv file if being created and the Word Template is there. When I
run the code for the first time all works great but then if I want to
print the document I get an error that the file is open. Only because
it never close properly. How can I make sure that WINWORD.EXE is
closed?
TIA,
Rodger