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 / Mailmerge and Fax / March 2005

Tip: Looking for answers? Try searching our database.

Problem with automating mail merge

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
HeatherO - 29 Mar 2005 16:59 GMT
I wanted to automate my mail merge and there is a problem it appears when I
am running my macro.  I have accessed excel through word using late binding
and stored all the mail merge data into 2 excel tables (one french, one
english).  I prompt for the english and french data files to use for the mail
merge.  When running it for some reason I get an error about another macro
called personal.xls in my excel application stating the file is in use and
locked for editing.  This macro though is seperate(the personal.xls) from the
mail merge macro but somehow it is causing interference.  A sample of my mail
merge is below: (any suggestions are appreciated)
Sub do_mail_merge(mrgfile_eng, mrgfile_fre)
Dim docname As String
Dim dtasrc As String
Dim filecnt As Long

XLShtEng.Activate
   lislrow = XLShtEng.Range("A65536").End(xlUP).Row
If lislrow >= 2 Then
  docname = mrgfile_eng
  dtasrc = "C:\Model Pilot\EngMrg.xls"
   filecnt = 1
GoTo labelZ
End If

labelZ:
     
   Documents.Open (docname)
   'Documents(docname).Activate
   With ActiveDocument.MailMerge
        .OpenDataSource name:=dtasrc, _
        ConfirmConversions:=False, ReadOnly:=True, LinkToSource:=True, _
        AddToRecentFiles:=False, PasswordDocument:="",
PasswordTemplate:="", _
        WritePasswordDocument:="", WritePasswordTemplate:="",
Revert:=False, _
        Format:=wdOpenFormatAuto, Connection:= _
        "Provider=Microsoft.Jet.OLEDB.4.0;Password="""";User ID=Admin;Data
Source=dtasrc;Mode=Read;Extended Properties=""HDR=YES;IMEX=1;"";Jet
OLEDB:System database="""";Jet OLEDB:Registry Path="""";Jet OLEDB:Database
Password="""";Jet OLEDB:Engine Type=3" _
        , SQLStatement:="SELECT * FROM `Sheet1$`", SQLStatement1:=""
        .Destination = wdSendToNewDocument
        .Execute
   End With
   Documents(docname).Activate
   ActiveDocument.Close wdDoNotSaveChanges
 
 
If filecnt < 2 Then
  lislrow = 0
  XLShtFre.Activate
  lislrow = XLShtFre.Range("A65536").End(xlUP).Row
  If lislrow >= 2 Then
     docname = mrgfile_fre
     dtasrc = "C:\Model Pilot\FreMrg.xls"
     filecnt = filecnt + 1
     GoTo labelZ
  End If
End If

XLBookENG.Close savechanges:=False
   XLBookFRE.Close savechanges:=False
 AppXL.Quit

Set XLBookENG = Nothing
Set XLBookFRE = Nothing

Set XLShtEng = Nothing
Set XLShtFre = Nothing

End Sub
Thanks,
Heather
Cindy M  -WordMVP- - 29 Mar 2005 21:50 GMT
Hi =?Utf-8?B?SGVhdGhlck8=?=,

> I wanted to automate my mail merge and there is a problem it appears when I
> am running my macro.  I have accessed excel through word using late binding
[quoted text clipped - 3 lines]
> called personal.xls in my excel application stating the file is in use and
> locked for editing.

If you're running this macro within the Excel environment, then you need to ask
this in an Excel newsgroup. To stop the people there from knee-jerking you back
here, mention the problem with the personal.xls FIRST, and in the subject line.
Then go on to say it's happening when you run code to automate Word, and post
the code. Don't forget to mention which version of Office you're using :-)

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :-)
HeatherO - 29 Mar 2005 22:11 GMT
Actually I am running the macro in word and accessing the excel application
through it.  However I think I now know why the mail merge is bombing out and
I am getting weird error messages that have nothing to do with what is really
going on, it is an excel thing though so I will try there.
Thanks for your help
Heather

> Hi =?Utf-8?B?SGVhdGhlck8=?=,
>
[quoted text clipped - 19 lines]
> This reply is posted in the Newsgroup; please post any follow question or reply
> in the newsgroup and not by e-mail :-)
 
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.