TextRange.InsertBarcode 方法 (Publisher)

會在父代 TextRange 物件所代表的文字範圍的結尾插入條碼欄位。

語法

運算式。InsertBarcode

運算式 代表 TextRange 物件的變數。

傳回值

TextRange

註解

理想狀況下,您應建立增益集至 Microsoft Publisher 處理 MailMergeGenerateBarcode 和 MailMergeInsertBarcode 事件。 如果您增益集或程式碼不包含這些事件處理常式, InsertBarcode 方法會傳回錯誤。

下列範例會示範如何在 Visual Basic Editor 中使用 Microsoft Visual Basic for Applications (VBA) 程式碼來處理這些事件。

如果您想要啟用出版物中插入條碼的從使用者介面,在增益集或 VBA 程式碼應該也 InsertBarcodeVisible 屬性值設定為 True。

範例

下列範例會示範如何使用 InsertBarcode 方法來插入文字] 方塊中的出版物中的列程式碼] 欄位。 您的 VBA 專案中插入下列程式碼和執行 InsertBarcode_Example 程序之前執行 AttachToEvents 程序。

在本例中執行程式碼、 之前使用 MailMerge.OpenDataSource 方法來連線至資料來源。 資料來源必須包含條碼列出所有合併列印收件者列程式碼行。 將程式碼中 MailMergeGenerateBarcode 事件處理常式中的 barcodeColumnIndex 取代為包含條碼資訊之資料來源欄的索引號碼。

從 Visual Basic 編輯器視窗執行下列程式碼,而不是從 [工具] 功能表上的 [巨集] 對話 (方塊執行,指向 [巨集],然後選擇 [巨集) ]。

Public WithEvents pubApplication As Publisher.Application 
 
Private Sub pubApplication_MailMergeGenerateBarcode(ByVal Doc As Document, bstrString As String) 
 
    bstrString = pubApplication.ActiveDocument.MailMerge.DataSource.DataFields.Item(barcodeColumnIndex).Value 
         
End Sub 
 
Private Sub pubApplication_MailMergeInsertBarcode(ByVal Doc As Document, OkToInsert As Boolean) 
 
    OkToInsert = True 
     
End Sub 
 
Public Sub InsertBarcode_Example() 
 
    Dim pubTextRange As Publisher.TextRange 
    Dim pubShape As Publisher.Shape 
     
    Set pubShape = ThisDocument.Pages(1).Shapes.AddTextbox(pbTextOrientationHorizontal, 100, 100, 500, 500) 
    Set pubTextRange = pubShape.TextFrame.TextRange 
     
    pubTextRange.InsertBarcode 
     
End Sub 
 
Public Sub AttachToEvents() 
 
    Set pubApplication = Application 
 
End Sub

支援和意見反應

有關於 Office VBA 或這份文件的問題或意見反應嗎? 如需取得支援服務並提供意見反應的相關指導,請參閱 Office VBA 支援與意見反應。