|
-
Feb 19th, 2014, 09:30 PM
#1
Thread Starter
New Member
Excel 2013 Macro Help - Open Template as Doc File instead of Template File
Hi
I have after much struggling and googling wrote a macro to do mail merge from Excel. It works well but I have one problem.
When Excel opens the word files it opens the actual template file, instead of say use that template to create a "Document1" or something.
This means that if one person is using this code to do mail merge, the file would be locked and no one else could use it.
Right now Excel opens the file itself, as if it rightclick and chose open, where it uses and alters the template.
Is there any way to have Excel open the file as if I were just doubleclicking the template file (which automatically creates a new unsaved file using the template) and run the mailmerge from that new file?
Thanks in advance.
Here's the code:
Set wdDoc = CreateObject("word.Application")
wdDoc.Documents.Open "Z:\XXXX\Labels Template - With New.dotx"
wdDoc.Visible = True
Dim OrderName As String
OrderName = ThisWorkbook.Path & "\" & ThisWorkbook.Name
On Error Resume Next
Set wdApp = GetObject(, "word.application")
If wdApp Is Nothing Then
Set wdApp = GetObject("Z:\XXXX\Labels Template - With New.dotx", "word.application")
End If
On Error GoTo 0
' Now you start opening the Word application and the document
With wdApp
Set wdDoc = wdApp.Documents.Open(Filename:="Z:\XXXX\Labels Template - With New.dotx")
wdDoc.Application.Visible = True
wdDoc.MailMerge.OpenDataSource _
Name:=OrderName, _
AddToRecentFiles:=False, _
Revert:=False, _
Format:=wdOpenFormatAuto, _
Connection:="Data Source=" & OrderName & ";Mode=Read", _
SQLStatement:="SELECT * FROM `Labels$`"
wdDoc.MailMerge.ViewMailMergeFieldCodes = wdToggle
With wdDoc.MailMerge
.MainDocumentType = wdFormLabels
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
.Execute Pause:=False
End With
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|