I'm using Acc XP VBA to open a Word mail merge doc which gets its data from an Excel spreadsheet. When the merge doc opens, I get a "Select Table" window requiring users to choose the data source in the Excel file. The two options are:
WorkSheetName
'WorkSheetName'
I'm trying to find a way to eliminate this step entirely so the document simply opens with the proper data link without any need for user involvement. So far, this is the latest code I'm using:
Dim oapp As Word.Application
Dim oword As Word.Document
'Update Excel sheet:
DoCmd.TransferSpreadsheet acExport, 8, "Query", "C:\Folder\File.xls", True, ""
Set oapp = CreateObject("Word.Application")
Set oword = oapp.Documents.Open(FileName:="C:\Folder\Doc.doc")
oapp.Visible = True
With oapp.ActiveDocument
If .MailMerge.DataSource.Name = "" Then
.MailMerge.OpenDataSource
(Name:="C:\Folder\File.xls", ConfirmConversions:=False, LinkToSource:=True, Format:=wdOpenFormatAuto, Connection:="WorkSheetName", SQLStatement:="", SQLStatement1:="", ReadOnly:=True)
.MailMerge.ViewMailMergeFieldCodes = False
End If
End With
Is there anything I can do to open the merge file in one click?
WorkSheetName
'WorkSheetName'
I'm trying to find a way to eliminate this step entirely so the document simply opens with the proper data link without any need for user involvement. So far, this is the latest code I'm using:
Dim oapp As Word.Application
Dim oword As Word.Document
'Update Excel sheet:
DoCmd.TransferSpreadsheet acExport, 8, "Query", "C:\Folder\File.xls", True, ""
Set oapp = CreateObject("Word.Application")
Set oword = oapp.Documents.Open(FileName:="C:\Folder\Doc.doc")
oapp.Visible = True
With oapp.ActiveDocument
If .MailMerge.DataSource.Name = "" Then
.MailMerge.OpenDataSource
(Name:="C:\Folder\File.xls", ConfirmConversions:=False, LinkToSource:=True, Format:=wdOpenFormatAuto, Connection:="WorkSheetName", SQLStatement:="", SQLStatement1:="", ReadOnly:=True)
.MailMerge.ViewMailMergeFieldCodes = False
End If
End With
Is there anything I can do to open the merge file in one click?