#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2017
    Location
    London
    Posts
    1
    Rep Power
    0

    Word Document Automation Using Content UI Editor (XML) & VBA - Assistance Needed


    Hi,

    If anyone could assist me with this challenge I would be eternally grateful. Happy to contribute something for your time. I just need to get one button working. Then I will be fine.

    I've recently been asked to automate the creation of a proposal document using Microsoft Word 2016.
    I've done it before so I thought I would do it again. I designed a ribbon bar with a sequence of buttons each having some VBA code behind them to perform the task.
    I didnt want employees to mess with the ribbon or the buttons so I utilised Content UI Editor from XMLOpenOrg to create the necessary ribbons and buttons within
    a MacroEnabled Microsoft Word document. The XML code creates the ribbon and its structor as shown below.

    STEPS

    So I create a standard blank word document
    I then Save it as a Macro Enabled Word File
    I then open the Macro Enabled file using Content UI Editor
    I then add the XML code to create the new ribbon and buttons I want, remembering to add the name of the
    macro "onAction='MacroName" which will be called when the button on the ribbon is pressed. (See futher down for VBA code)

    This is the XML code I use once the Macro Enables Word File has been opened in Content UI Editor.

    <customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui">
    <ribbon startFromScratch="false">
    <tabs>
    <tab id="customTab" label="PDT Proposal">
    <group id="Content" label="Document Introduction">
    <button id="content1" label="Title Page" size="large" onAction="Insert_TitlePage" image="GeneralDocument_Icon" />
    <button id="content2" label="Why PDT Global" size="large" onAction="Insert_WhyPGTGlobal" image="content_page" />
    <button id="content3" label="Client Requirements" size="large" onAction="Insert_Requirements" image="content_page"/>
    <button id="content4" label="Delivery Methods" size="large" onAction="Insert_Delivery_Methods" image="content_page"/>
    <button id="content5" label="Proposal Programme" size="large" onAction="Insert_Proposal_Programme" image="content_page"/>
    <button id="content6" label="Discovering UB" size="large" onAction="Insert_DiscoverUB" image="content_page"/>
    <button id="content7" label="UB for All" size="large" onAction="Insert_UB4ALL" image="content_page"/>
    </group>
    </tab>
    </tabs>
    </ribbon>
    </customUI>

    I then save the document.
    Exit out of the Content UI Editor application and then open the macro enabled word document.
    When the word document is opened the Ribbon Appears as do the buttons. Great!

    Behind each button sits the VBA code which instructs word to access the BlockBuilder Function
    and inserts the predefined items of text | tables | icons and graphics.I wish to be inserted

    This is the VB Code that I am using.

    Sub Insert_TitlePage(control As IRibbonControl)
    Call InsertPageBreak
    ActiveDocument.AttachedTemplate.BuildingBlockEntries("001_Insert_TitlePage").Insert _
    Where:=Selection.Range
    End Sub

    Sub Insert_WhyPDTGlobal(control As IRibbonControl)
    ActiveDocument.AttachedTemplate.BuildingBlockEntries("002_WhyPDTGlobal").Insert _
    Where:=Selection.Range
    End Sub

    Sub Insert_Requirements(control As IRibbonControl)
    ActiveDocument.AttachedTemplate.BuildingBlockEntries("003_Requirements").Insert _
    Where:=Selection.Range

    End Sub

    Sub Insert_ProposalProgramme(control As IRibbonControl)

    ActiveDocument.AttachedTemplate.BuildingBlockEntries("004_ProposalProgram").Insert _
    Where:=Selection.Range

    End Sub

    Sub Insert_DiscoverUB(control As IRibbonControl)

    ActiveDocument.AttachedTemplate.BuildingBlockEntries("005_Discover_UB").Insert _
    Where:=Selection.Range

    End Sub

    Sub Insert_UB4ALL(control As IRibbonControl)

    ActiveDocument.AttachedTemplate.BuildingBlockEntries("006_UB4ALL").Insert _
    Where:=Selection.Range

    End Sub

    Sub Insert_DeliveryMethods(control As IRibbonControl)

    ActiveDocument.AttachedTemplate.BuildingBlockEntries("007_DeliveryMethods").Insert _
    Where:=Selection.Range

    End Sub

    HERE IS MY PROBLEM

    Each time I click a button in the document to run the VBA Code.
    I get this Microsoft Visual Basic for Applications dialogue box with a Red Circle and X in the
    middle with no error message explaining what action to take next. Having tried everything I know
    I decided to resort to a forum of experts who might be able to shed some light on the issue.

    I'm using Windows 10 Professional
    Microsoft Word v2016
    Content UI Editor (Download Link: http://openxmldeveloper.org/cfs-file...ditorSetup.zip)
    Useful Link: https://social.msdn.microsoft.com/Fo...?forum=worddev

    Your assistance is both respected and greatly appreciated.

    Many thanks in advance.

    Mark Jones
  2. #2
  3. Lazy Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,437
    Rep Power
    9645
    Originally Posted by JonesMark1974
    Each time I click a button in the document to run the VBA Code.
    I get this Microsoft Visual Basic for Applications dialogue box with a Red Circle and X in the
    middle with no error message explaining what action to take next.
    Set a breakpoint in VBA for the first line in the method corresponding to whatever button you want to use, then press it. You should jump into VBA with execution paused. "Step into" it line by line until some error occurs.

IMN logo majestic logo threadwatch logo seochat tools logo