How to get handle to new document instance RRS feed

  • Question

  • 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.

    Sunday, November 17, 2013 7:05 AM


  • Try something based on:

    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)
        With wdDoc
        ' Do whatever here
        End With
    End With
    End Sub

    Paul Edstein
    [MS MVP - Word]

    Tuesday, November 19, 2013 9:45 AM