Ken Puls
Active Member
- Joined
- Jun 9, 2003
- Messages
- 484
Hello,
I've been having a little fun trying to build a macro to print mailing labels from Excel via a Microsoft Word template. My code works sometimes, which is a little frustrating as I'd really prefer it to work all the time! I've think I've figured out the Early vs Late bind on this, and have opted for an early bind. (A reference is set to the Microsoft Word 11.0 Object Library as I am using Office 2003.)
Here's the code:
(I hope it doesn't blow apart text wrapping as I ran into issues trying to wrap the OpenDataSource part so just set it back to what works.)
So here's the issue:
The first time I run the macro, I get a "Runtime error '462' The remote server machine does not exist or is unavailable"
What's weird is that if I run it again immediately, it works beautifully. Can anyone tell me what is going wrong here?
Thanks,
I've been having a little fun trying to build a macro to print mailing labels from Excel via a Microsoft Word template. My code works sometimes, which is a little frustrating as I'd really prefer it to work all the time! I've think I've figured out the Early vs Late bind on this, and have opted for an early bind. (A reference is set to the Microsoft Word 11.0 Object Library as I am using Office 2003.)
Here's the code:
Code:
Sub testwordcall()
Dim WordApp As Word.Application
Set WordApp = CreateObject("Word.Application")
With WordApp
.Visible = True
.Documents.Add Template:="F:\templates\FW Centre\MemberRenewalLabels.dot", _
NewTemplate:=False, DocumentType:=0
With ActiveDocument.MailMerge
.OpenDataSource Name:="J:\Members Addresses.xls", _
ConfirmConversions:=False, ReadOnly:=False, 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=J:\Members Addresses.xls;Mode=Read;Extended Properties=""HDR=YES;IMEX=1;"";Jet OLEDB:System database="""";Jet OLEDB:Registry Path="""";Jet OLEDB:Database Password="""";Jet OLEDB:Engine Type=35" _
, SQLStatement:="SELECT * FROM `MailMergeData$`", SQLStatement1:="", _
SubType:=wdMergeSubTypeAccess
.Destination = wdSendToPrinter
.SuppressBlankLines = True
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute Pause:=False
End With
.Quit False
End With
End Sub
(I hope it doesn't blow apart text wrapping as I ran into issues trying to wrap the OpenDataSource part so just set it back to what works.)
So here's the issue:
The first time I run the macro, I get a "Runtime error '462' The remote server machine does not exist or is unavailable"
What's weird is that if I run it again immediately, it works beautifully. Can anyone tell me what is going wrong here?
Thanks,