Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / November 2006

Tip: Looking for answers? Try searching our database.

Select Table window interrupts macro

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Straws - 31 Oct 2006 21:50 GMT
Hi,
I am automating a mailmerge from a datasheet in excel to a word document.  
The user enters data into the excel spreadsheet and then uses a userform to
activate the mailmerge process.

my code is interrupted when the Word main document is opened and the
datasource is being defined.  Word pops up a window called "Select Table"
which (surprise surprise) allows you to select which worksheet the data is on
in the excel workbook.

I can't figure out how to automate this selection... I want to be selecting
"sheet1"... and it's the only sheet in the workbook so I don't understand why
it doesn't just select it automatically.

I won't post all the code at the moment cause I don't think it's entirely
relevant to the problem, but if anyone wants it then I would be happy to.

Here is the part that seems to be relevant.
   With appWD.ActiveDocument.MailMerge
       .OpenDataSource Name:=(Workbooks("whatson data").Path & "\Guts - do_
not tamper\Data Source.xls")
       .DataSource.FirstRecord = 1
       .DataSource.LastRecord = r - 3
       .Destination = wdSendToNewDocument
       .Execute
   End With

I have searched the message board here and at mrexcel but can find no-one
who has had a similar problem... which leads me to suspect I'm doing
something wrong.  However, time (and your responses) will tell.

Thanks SO much to anyone who can help me with this one.

Straws.
Straws - 01 Nov 2006 20:53 GMT
Errr,   So is this too hard?  
Or am I asking the wrong question somehow?

Someone *please* help
Doug Robbins - Word MVP - 02 Nov 2006 08:03 GMT
Recording the action of attaching Sheet 1 of an Excel file as the data
source for a mailmerge produces the following code:

   ActiveDocument.MailMerge.OpenDataSource Name:= _
       "C:\Documents and Settings\Doug Robbins\My Documents\My Data
Sources\Book1.xls" _
       , ConfirmConversions:=False, ReadOnly:=False, LinkToSource:=True, _
       AddToRecentFiles:=False, PasswordDocument:="", PasswordTemplate:="",
_
       WritePasswordDocument:="", WritePasswordTemplate:="", Revert:=False,
_
       Format:=wdOpenFormatAuto, Connection:= _
       "Provider=Microsoft.ACE.OLEDB.12.0;User ID=Admin;Data
Source=C:\Documents and Settings\Doug Robbins\My Documents\My Data
Sources\Book1.xls;Mode=Read;Extended Properties=""HDR=YES;IMEX=1;"";Jet
OLEDB:System database="""";Jet OLEDB:Registry Path="""";Jet OLEDB:Eng" _
       , SQLStatement:="SELECT * FROM `Sheet1$`", SQLStatement1:="",
SubType:= _
       wdMergeSubTypeAccess

As that was recorded in Word 2007, it may not be 100 percent appropriate for
the version that you are using so I would suggest that you record the same
action for yourself.

Signature

Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

> Hi,
> I am automating a mailmerge from a datasheet in excel to a word document.
[quoted text clipped - 35 lines]
>
> Straws.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.