none
Import Building Blocks at bookmarked location in MS Word based on dropdown selection from a combobox or listbox RRS feed

  • Question

  • Hello everyone,

    I'm using Word 2007 and Visual Basic Express 2010.

    I have a form that I'm creating which requires this one last thing to be dealt with before I can finish it.  What I'm doing is creating a form that uses letter templates.  At the bottom of each letter (where bookmarked) I want the image of someone's signature to appear based on the name selected in a listbox or combobox.  There will be about 7 different names to choose from.  Anyone able to help me out with some code to make this happen?

    I want something like the below to appear for each name (my drawing in paint belongs in an art gallery, right?):

    <Image of signature here>

    <Signor's name in text here>

    <Signor's job title in text here>

    <Signor's initials>

    Thank you!

    Wednesday, May 9, 2012 11:32 AM

Answers

  • Because you have only 7 names, I would keep this simple and avoid using code.

    Where it says

    <Signor's name in text here>

    insert a DropDown list from the Developer tab, then select it to modify its properties (From the Contrition group on the Developer tab).

    Check "Content Control cannot be deleted" then add the 7 names using the same dialogue (at the bottom).

    Then, with the Control still selected, Go to the Insert tab, and in the Link group click on Bookmark, add a Bookmark, something like "CheckName"

    Finally, where it says

    <Image of signature here>

    or

    <Signor's job title in text here>

    <Signor's initials>

    use nested IF fields, like this (Here I am using an example with only two names...):

    {IF {CheckName} = "John Doe" "Actual gif/jpg of Doe's signature" "{IF {CheckName} = "Peter Smith" "Actual gif/jpg of Smith's signature" "Select a name"}"}

    And so on.

    Note that once you have selected a name, you need to select the IF fields and do an update...

    No need for code!

    • Marked as answer by MBuchok Wednesday, May 9, 2012 7:51 PM
    • Unmarked as answer by MBuchok Wednesday, May 16, 2012 1:48 PM
    • Marked as answer by MBuchok Friday, May 18, 2012 11:50 PM
    Wednesday, May 9, 2012 2:22 PM
  • Assuming Userform listbox and a bookmark named "bmImageHere" then something like this:

    Option Explicit
    Private Sub ListBox1_Click()
    Set oTemplate = ActiveDocument.AttachedTemplate
    Dim oRng As Word.Range
    Set oRng = oTemplate.BuildingBlockTypes(wdTypeCustom1).Categories("Signatures"). _
             BuildingBlocks(Me.ListBox1.ListIndex + 1).Insert(ActiveDocument.Bookmarks("bmImageHere").Range)
    ActiveDocument.Bookmarks.Add "bmImageHere", oRng
    End Sub

    Private Sub UserForm_Initialize()
    With Me.ListBox1
      .AddItem "George Washington"
      .AddItem "Abraham Lincoln"
      .AddItem "Elmer Fudd"
    End With
    End Sub

    The first building block in the category "Signature" in the wdTypeCustom1 gallery is an image of George Washington's signature and so on.


    Greg Maxey Please visit my website at: http://gregmaxey.mvps.org/word_tips.htm

    • Marked as answer by MBuchok Friday, May 18, 2012 11:50 PM
    Tuesday, May 15, 2012 10:14 PM

All replies

  • I don't think you need programming for this. Check out Words building block feature. Save the different signatures as buildningblocks and use a buildingblock content control in the document.

    /Peeter

    Wednesday, May 9, 2012 2:09 PM
  • Because you have only 7 names, I would keep this simple and avoid using code.

    Where it says

    <Signor's name in text here>

    insert a DropDown list from the Developer tab, then select it to modify its properties (From the Contrition group on the Developer tab).

    Check "Content Control cannot be deleted" then add the 7 names using the same dialogue (at the bottom).

    Then, with the Control still selected, Go to the Insert tab, and in the Link group click on Bookmark, add a Bookmark, something like "CheckName"

    Finally, where it says

    <Image of signature here>

    or

    <Signor's job title in text here>

    <Signor's initials>

    use nested IF fields, like this (Here I am using an example with only two names...):

    {IF {CheckName} = "John Doe" "Actual gif/jpg of Doe's signature" "{IF {CheckName} = "Peter Smith" "Actual gif/jpg of Smith's signature" "Select a name"}"}

    And so on.

    Note that once you have selected a name, you need to select the IF fields and do an update...

    No need for code!

    • Marked as answer by MBuchok Wednesday, May 9, 2012 7:51 PM
    • Unmarked as answer by MBuchok Wednesday, May 16, 2012 1:48 PM
    • Marked as answer by MBuchok Friday, May 18, 2012 11:50 PM
    Wednesday, May 9, 2012 2:22 PM
  • Arrrggghhh, of course, where it says

    "From the Contrition group on the Developer tab"

    I meant;

    "From the Controls group on the Developer tab"

    Wednesday, May 9, 2012 2:24 PM
  • I have a follow-up on this for you...

    When setting these up within the template itself, it works, but when I open a new document based on the template, the building blocks don't appear.  Any idea why this is?

    Also, I think I would actually like to see how I could programatically do this in code.  Are you able to demonstrate an example for me?

    Tuesday, May 15, 2012 5:59 PM
  • Where did you saved the Buiding Blocks?

    I think in your case is better to save them in your template.

    Lauro

    Tuesday, May 15, 2012 8:47 PM
  • The difficulty with that is, when the building blocks are saved to the template, and I open another instance of the template as Document1, the field codes do not recognize the building blocks.  If I use the building blocks within the actual physical template (and not a new document based on that template) it works just fine.

    I've programatically done this in VB6, but now would like to see the exact same thing in VB.Net

    I get how making this work without programming is easier, but functionally I believe programming the signatures the way I need will be best for my project.  I would like to use a combobox with names, then based on the selection, populate at a bookmark with the image of the associated signature.

    Tuesday, May 15, 2012 8:59 PM
  • Assuming Userform listbox and a bookmark named "bmImageHere" then something like this:

    Option Explicit
    Private Sub ListBox1_Click()
    Set oTemplate = ActiveDocument.AttachedTemplate
    Dim oRng As Word.Range
    Set oRng = oTemplate.BuildingBlockTypes(wdTypeCustom1).Categories("Signatures"). _
             BuildingBlocks(Me.ListBox1.ListIndex + 1).Insert(ActiveDocument.Bookmarks("bmImageHere").Range)
    ActiveDocument.Bookmarks.Add "bmImageHere", oRng
    End Sub

    Private Sub UserForm_Initialize()
    With Me.ListBox1
      .AddItem "George Washington"
      .AddItem "Abraham Lincoln"
      .AddItem "Elmer Fudd"
    End With
    End Sub

    The first building block in the category "Signature" in the wdTypeCustom1 gallery is an image of George Washington's signature and so on.


    Greg Maxey Please visit my website at: http://gregmaxey.mvps.org/word_tips.htm

    • Marked as answer by MBuchok Friday, May 18, 2012 11:50 PM
    Tuesday, May 15, 2012 10:14 PM
  • Hi Greg,

    Thanks for your reply, but do you have a version of this for VB.Net? 

    In fact, you helped me with this not too long ago with an older version of VB.  Please see link below...

    http://answers.microsoft.com/en-us/office/forum/office_2010-word/userform-command-button-to-import-image-at-a/2087ca18-86fc-4e1c-8b66-835bae46a891

    I'd like the same effect as what you provided in this link, except in VB.Net

    • Edited by MBuchok Wednesday, May 16, 2012 3:04 PM
    Wednesday, May 16, 2012 2:51 PM
  • My answer did not rely on building blocks at all, so I am not sure why you are using them.

    For the code, see Greg's reply, it will be very easy to port the VBA to VB.Net.

    Wednesday, May 16, 2012 3:19 PM
  • It turns out that I'm an idiot and used the building blocks out of habit and didn't think of just inserting the pictures into the fields from file.

    I'll reply back when I've had a chance to try and port from VBA to VB.Net... if I can't seem to figure that out, then I'll use your suggestion of using the dropdown with bookmarks.

    Thanks again.

    Wednesday, May 16, 2012 4:10 PM
  • Unfortunately I don't even know what VB.Net is.  Sorry.

    Greg Maxey Please visit my website at: http://gregmaxey.mvps.org/word_tips.htm

    Wednesday, May 16, 2012 9:06 PM
  • I figured out a good way to go about this:

    I just populated a docvariable field from a combobox with the person's name, then when the name is entered into the template I then used the 'IF' statements to produce the image of the signatures as suggested.  I also already have an update fields command in my code, so updating the fields is no longer a problem.  Ultimately, I'd say the first suggestion was the best one as you showed me something I never thought you could do with an 'IF' statement before... I thought those fields were meant just for text.

    Thanks again for your help everyone.  Much appreciated.


    • Edited by MBuchok Friday, May 18, 2012 11:49 PM
    Friday, May 18, 2012 11:49 PM