VBA для издателя против Word

Пытаюсь создать макрос для копирования данных из Excel в MS Publsiher. У меня есть код для MS Word, но он не работает при применении к Publisher. В этой строке происходит сбой appPub.ActiveWindow.Bookmarks("Growth").Paste

Word VBA:

    Sub SendData()
    Dim WordApp As Object
    Set WordApp = CreateObject("Word.Application")
    Dim ws As Worksheet
    ' Sheet1 is the codename for the sheet with the named range you want to copy,
    ' this is the name of the sheet in brackets in the VBAProject explorer, not the
    ' friendly name given on the worksheet tab itself visible to the end user.
    Set ws = Sheet4
    ' This is the constant string which holds the filepath to your Word document
    Const WORDDOC As String = "C:\Quarterly Reports - Word Version\Growth.docx"

    WordApp.Visible = True

    WordApp.Documents.Open WORDDOC

    ' Copies the named range "OrderRange" from the Excel book 
        'you are running this from.
    ws.Range("Growth").Copy
    ' Pastes it to the bookmark "OrderBookmark" in your Word doc template.
    WordApp.ActiveDocument.Bookmarks("Growth").Range.PasteAppendTable
    ' Sets your printer in Word to Adobe PDF and then prints the whole doc.
    ' WordApp.ActivePrinter = "Adobe PDF"
    ' WordApp.ActiveDocument.PrintOut
    Set WordApp = Nothing
    End Sub

Издатель VBA:

    Sub SendDataPB()
    Dim appPub As Object
    Set appPub = CreateObject("Publisher.Application")
    Dim ws As Worksheet
    ' Sheet1 is the codename for the sheet with the named range you want to copy,
    ' this is the name of the sheet in brackets in the VBAProject explorer, not the
    ' friendly name given on the worksheet tab itself visible to the end user.
    Set ws = Sheet4
    ' This is the constant string which holds the filepath to your Publisher document
    Const PublisherDOC As String = "C:\Quarterly Reports - Publisher     Version\Growth.pub"

    appPub.ActiveWindow.Visible = True

    appPub.Open PublisherDOC

    ' Copies the named range "OrderRange" from the Excel book
    '     you are running this from.
    ws.Range("Growth").Copy
    ' Pastes it to the bookmark "OrderBookmark" in your Publisher doc template.
    appPub.ActiveWindow.Bookmarks("Growth").Paste
    ' Sets your printer in Publisher to Adobe PDF and then prints the whole doc.
    ' PublisherApp.ActivePrinter = "Adobe PDF"
    ' PublisherApp.ActiveDocument.PrintOut
    Set appPub = Nothing
    End Sub

person Sarah Broaden    schedule 15.10.2013    source источник
comment
Никогда раньше не работал с Publisher, но я понял, что закладки в Publisher — это не то же самое, что закладки Word. Это формы .Type как pbWebHTMLFragment и .AutoShapeType как msoShapeMixed. Я полагаю, что вы могли бы создать шаблон слова, а затем сохранить его как файл .Pub?   -  person Siddharth Rout    schedule 16.10.2013
comment
Только что проверил в Publisher. Во всплывающей подсказке Bookmark написано Bookmark appears as graphical elements on the page, and allow you to add hyperlinks to that location in the publication   -  person Siddharth Rout    schedule 16.10.2013
comment
Как вы думаете, вы могли бы написать vba, чтобы указать на гиперссылку? Я не могу сделать это в слове и сохранить как издатель, потому что шаблон специально разработан для издателя и искажается в слове. Я не могу найти много о vba в издателе...   -  person Sarah Broaden    schedule 21.10.2013
comment
Как это поможет? Насколько я понял (и могу ошибаться), но вы не можете вставить текст в эту закладку...   -  person Siddharth Rout    schedule 21.10.2013


Ответы (1)


Похоже, что ActiveWindow не содержит коллекции .Bookmarks: https://msdn.microsoft.com/EN-US/library/office/ff939707.aspx

Попробуйте ActiveDocument.Pages(YourPage).Shapes.Paste, возможно... Если повезет, скопированная таблица будет вставлена ​​как новая фигура. С этого момента вам просто нужно будет придумать умный способ размещения и поиска заполнителей, если только вам не удастся найти пригодную для использования коллекцию закладок где-то еще в объектной модели... Удачи!

person Jbjstam    schedule 22.09.2015