Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trouble with Acc VBA automation of Word

Status
Not open for further replies.

Dor100

Technical User
Apr 9, 2001
279
US
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?
 
No success yesterday. Anyone know how to programmatically dismiss that Select Table window so the user can simply click open the file?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top