BillHamilton
05-02-2015, 05:03 AM
Hi,
I have an Excel macro that opens Word and using Word macro code creates a mailing label document from one of Word's built-in templates then writes data held in an array to it (each label is different). Here's the code (excluding writing out the data which is quite complicated and irrelevant here):
Sub WriteToWordFile()
Dim objWord As Object, Wrd As Word.Application, Doc As Word.Document
On Error Resume Next
Set objWord = GetObject(, "Word.Application")
If Not objWord Is Nothing Then
objWord.Quit
Set objWord = Nothing
End If
On Error GoTo 0
Set Wrd = New Word.Application
Set Doc = Wrd.Documents.Add
' Why does the following instruction take about a minute to execute? <<<<<<<<<<<<<<<<<<
Wrd.MailingLabel.CreateNewDocument Name:="J8651", Address:="", _
AutoText:="", LaserTray:=wdPrinterManualFeed, ExtractAddress:=False, _
PrintEPostageLabel:=False, Vertical:=False
' Code to write data to each label in the Document.
Wrd.ActiveDocument.SaveAs Filename:="LabelFile"
End Sub
Pretty standard stuff.
I only run this once a year to create the labels for an annual occasion, and this year I've discovered from stepping though the code that it takes a whole minute just to execute the instruction
"Wrd.MailingLabel.CreateNewDocument Name:="J8651", Address:="", _
AutoText:="", LaserTray:=wdPrinterManualFeed, ExtractAddress:=False, _
PrintEPostageLabel:=False, Vertical:=False"
whereas previously it just floated through with hardly a pause. This code was originally created by the macro generator..
I have recently upgraded from Office 2007 to Office 2013 and this is the first time it has run under that version. Using Windows 7.
Has anyone any clues as to why this is happening and what to do about it?
Bill
I have an Excel macro that opens Word and using Word macro code creates a mailing label document from one of Word's built-in templates then writes data held in an array to it (each label is different). Here's the code (excluding writing out the data which is quite complicated and irrelevant here):
Sub WriteToWordFile()
Dim objWord As Object, Wrd As Word.Application, Doc As Word.Document
On Error Resume Next
Set objWord = GetObject(, "Word.Application")
If Not objWord Is Nothing Then
objWord.Quit
Set objWord = Nothing
End If
On Error GoTo 0
Set Wrd = New Word.Application
Set Doc = Wrd.Documents.Add
' Why does the following instruction take about a minute to execute? <<<<<<<<<<<<<<<<<<
Wrd.MailingLabel.CreateNewDocument Name:="J8651", Address:="", _
AutoText:="", LaserTray:=wdPrinterManualFeed, ExtractAddress:=False, _
PrintEPostageLabel:=False, Vertical:=False
' Code to write data to each label in the Document.
Wrd.ActiveDocument.SaveAs Filename:="LabelFile"
End Sub
Pretty standard stuff.
I only run this once a year to create the labels for an annual occasion, and this year I've discovered from stepping though the code that it takes a whole minute just to execute the instruction
"Wrd.MailingLabel.CreateNewDocument Name:="J8651", Address:="", _
AutoText:="", LaserTray:=wdPrinterManualFeed, ExtractAddress:=False, _
PrintEPostageLabel:=False, Vertical:=False"
whereas previously it just floated through with hardly a pause. This code was originally created by the macro generator..
I have recently upgraded from Office 2007 to Office 2013 and this is the first time it has run under that version. Using Windows 7.
Has anyone any clues as to why this is happening and what to do about it?
Bill