Results 1 to 5 of 5
  1. #1
    New Lounger
    Join Date
    Jan 2001
    Location
    Grand Rapids, Michigan, USA
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I'm a self-taught VBA person and am working on migrating our firm to Office 2007. Instead of just using "what worked" in 2003 I'm trying to create our 2007 templates using the new features but I'm now stuck on something.

    We have a global autotext template in the startup directory. With Office 2007 I thought I'd create a couple global Building Blocks (footer for our letterhead, etc.) but now I can't seem to write the correct code to insert that footer.

    Here's the code I'm trying - it actually works, but I receive an error so something's not quite right. I've tried a few different variations. I did try specifying the attached template but must not have had that code right - again it worked, but I received an even different error message.

    With this code, the footer is inserted but the error is "Run-time error 5941. The requested member of the collection does not exist." and it hangs on the line "Set objBB..."

    Thanks for any help - I truly appreciate it!!
    Julie


    The footer I created is called .ftrFirmLocations
    Our category for firm building blocks is (firm)

    Dim objTemplate As Template
    Dim objBB As BuildingBlock

    'set template to store the building block
    Set objTemplate = ActiveDocument.AttachedTemplate

    'access the building bock through the type and category
    Set objBB = objTemplate.BuildingBlockTypes(wdTypeFooters) _
    .Categories("(firm)").BuildingBlocks(".ftrFirmLoca tions")

    'insert the building block into the document
    objBB.Insert Selection.Range

  2. #2
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts
    Is there multiple building blocks with the same name but in different categories? If not, I would try
    Set objBB = objTemplate.BuildingBlockEntries.Item(".ftrFirmLoc ations")

    If that doesn't work, then you might want to try with an item that has a name that doesn't start with a period (fullstop). I am mildly surprised you can name an item that way and it could be the source of the problem so best to eliminate that possibility early.

    I haven't used the BuildingBlock object before but they appear to be much the same thing as an Autotext Entry so you could also try.
    objTemplate.AutoTextEntries(".ftrFirmLocations").I nsert Where:=Selection.Range, RichText:=True
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  3. #3
    New Lounger
    Join Date
    Jan 2001
    Location
    Grand Rapids, Michigan, USA
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks. It's still not quite right. I get the error "Requested member of collection does not exist" but it does actually work.

    I did check & I don't have two building blocks named the same. and I did take the period out of the name. I'm sure it's something I'm missing because I don't know enough.


    Thanks again!
    Julie

  4. #4
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts
    Looking back again at your first post, you say you are putting the building block entry into a template located in the startup directory. If this is the case then the building block is NOT located in the AttachedTemplate so we should expect an error with your (and my) code. You will need to specify the correct template where the relevant Building Block is located. You will need the full file path for a global template.
    Try the following
    Dim objTemplate As Template
    Dim objBB As BuildingBlock

    'set template to store the building block
    Set objTemplate = Templates("C:\folder\GlobalTemplate.dotx")

    'access the building bock through the type and category
    Set objBB = objTemplate.BuildingBlockEntries.Item(".ftrFirmLoc ations")

    'insert the building block into the document
    objBB.Insert Selection.Range
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  5. #5
    New Lounger
    Join Date
    Jan 2001
    Location
    Grand Rapids, Michigan, USA
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you - we had another project come up so I'm just now getting back to this one. I'll give this a shot...
    Julie

    [quote name='Andrew Lockton' post='765185' date='12-Mar-2009 20:59']Looking back again at your first post, you say you are putting the building block entry into a template located in the startup directory. If this is the case then the building block is NOT located in the AttachedTemplate so we should expect an error with your (and my) code. You will need to specify the correct template where the relevant Building Block is located. You will need the full file path for a global template.
    Try the following[/quote]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •