PDA

View Full Version : How to get handle to new document instance



BrandonR
11-16-2013, 11:15 PM
Hi Everyone,

I'd appreciate some help with this coding question.

Requirement: Using VBA, I want to create a new mailing label document, and automatically type text into the new document, then save it. I generated the following code using the Macro recording feature, and it properly creates the document (using the Avery L7165 label layout).

Problem: I know how to use VBA to place text into a document and to save a document, but I can't figure out how to get a handle on the newly created document. Please note that I don't want to use any mail merge functionality.

Sub Test()

Application.MailingLabel.DefaultPrintBarCode = False
Application.MailingLabel.CreateNewDocumentByID LabelID:="805957278", _
Address:="", AutoText:="", LaserTray:=wdPrinterManualFeed, ExtractAddress _
:=False, PrintEPostageLabel:=False, Vertical:=False

End Sub

Thanks in advance for any guidance provided.

Brandon

macropod
11-17-2013, 03:10 AM
You do it like so:

Sub Test()
Dim wdDoc As Document
With Application.MailingLabel
.DefaultPrintBarCode = False
Set wdDoc = .CreateNewDocumentByID(LabelID:="805957278", Address:="", _
AutoText:="", LaserTray:=wdPrinterManualFeed, ExtractAddress:=False, _
PrintEPostageLabel:=False, Vertical:=False)
End With
MsgBox wdDoc.Name
End Sub

BrandonR
11-17-2013, 02:30 PM
Thanks very much! I'll try it.


You do it like so:
...