2013-10-15 5 views
1

Попытка создания макроса для копирования данных из Excel в MS Publsiher. У меня есть код для MS Word, но он не работает, когда применяется к издателю. . Она терпит неудачу на этой линии appPub.ActiveWindow.Bookmarks ("Growth") ПастаVBA for Publisher vs 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 
+0

Никогда не работал с издателем раньше, но я мог понять, что закладки в Publisher не совпадают с записями Word. Они являются формами '.Type' как' pbWebHTMLFragment' и '.AutoShapeType' как' msoShapeMixed'. Я считаю, что вы могли бы создать шаблон слова, а затем сохранить его как файл '.Pub'? –

+0

Только что зарегистрировался в издательстве. В подсказке «Закладка» говорится: «Закладка отображается в виде графических элементов на странице и позволяет добавлять гиперссылки в это место в публикации» –

+0

. Как вы думаете, сможете ли вы написать vba, чтобы указать на гиперссылку? Я не могу делать это в словах и сохранять как издатель, потому что шаблон специально разработан для издателя и искажается словом. Я не могу много узнать о vba в издателе ... –

ответ

0

ActiveWindow не кажется для хранения любой коллекции .Bookmark: https://msdn.microsoft.com/EN-US/library/office/ff939707.aspx

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