Results 1 to 12 of 12
  1. #1
    2 Star Lounger
    Join Date
    Oct 2007
    Posts
    172
    Thanks
    0
    Thanked 2 Times in 1 Post

    Adding Shapes to Footers (Word 2003 VB)

    OK, I have been playing/struggling for a few days to get some code to work in which i am trying to add and remove images to footers automatically. It is made more complicated by the fact that the document template already has one "logo" in the footer and I want to be able to add and remove a second one at will, without affecting the one thats there already.

    I am now questioning my whole approach, which is based on looping through each page, and if its the beginning of a section, determine if there is a different first page footer, or different odd and even footers, then adding an image in the appropriate place accordingly. The difficulty is in removing the image afterwards. QUESTION: am i right in thinking that the only way to identify the image that I previously added is by using its "Name" property?

    If so, each image that I add to the footer in each section and footer index has to have a unique name.. that means naming them and then deleting them by name later isn't straightforward. I also don't know the names of the fixed logos that are already in the footer and must be retained, since they were added manually into the template and have names like "Picture 42"...

    Basically at the moment I am naming the images by creating a name based on a fixed string & a random number (which is most probably unique!). I then locate the images to delete based on the fixed string part of the name.

    This seems to work fine for the whole document except for the very first page of the document, where I add a Shape object to the footer range, but I then can't find it again.. :-(

    So after that ramble, can anyone confirm my approach or suggest a different one that isn't error prone or uses random numbers!!?

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Adding Shapes to Footers (Word 2003 VB)

    The only other parameters I think you can set are the position and size (for shapes, that is, "floating" images). You might use those to identify your images if they are likely to be unique.

  3. #3
    2 Star Lounger
    Join Date
    Oct 2007
    Posts
    172
    Thanks
    0
    Thanked 2 Times in 1 Post

    Re: Adding Shapes to Footers (Word 2003 VB)

    Thanks - yeah i had already thought of that but i didn't want to prejudice any replies by saying it! To me that approach seems more unreliable than using a generated "most likely unique" name.

  4. #4
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,054
    Thanks
    2
    Thanked 417 Times in 346 Posts

    Re: Adding Shapes to Footers (Word 2003 VB)

    Hi dom_donald,

    I'd suggest that you start off by giving the logo shape a meaningful name (eg "Logo") - before you add any new shapes. You can change the name assigned by Word using vba. Then, when you want to delete the other shape(s), you can use a loop with a simple IF test to delete any shape(s) without that name.
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Adding Shapes to Footers (Word 2003 VB)

    I was going to suggest the same as macropod, so I'll just say that I second his suggestion.

  6. #6
    2 Star Lounger
    Join Date
    Oct 2007
    Posts
    172
    Thanks
    0
    Thanked 2 Times in 1 Post

    Re: Adding Shapes to Footers (Word 2003 VB)

    marvellous. Thanks guys.. One problem though..

    the "fixed" logo appears in every footer. That means there are actually three fixed logo images in one section (different odd/even footers and different first page). The images have to have unique numbers, so I am back to the same problem as I have at the moment i.e. having to generate names using a fixed string and a random number. I mean, its just as easy to delete a set of images whose names contain a string as it is to leave a set of images whose names contain a string.

    Your suggestion does have an advantage though - if the user were to enter a second logo manually, I could still delete them automatically later. My current code wouldn't be able to do this becuase the manually entered images wouldn't conform to the necessary naming convention.

    That leads me to my final question on this (!)... can I "protect" my "fixed" logo to stop people deleting it manually? If I can do this, I will switch my code to your suggested method as it is more reliable. If I can't, and the user can manually delete and add the logos anyway, then the whole exercise is flawed because I can't force people to use the macro to add the images!

  7. #7
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Adding Shapes to Footers (Word 2003 VB)

    You cannot keep users from manually adding and removing shapes in the header or footer, unless you protect the document for forms. A macro could still unprotect the document, manipulate shapes and reprotect the document.
    But even in unprotected sections in a protected document, users are limited in other ways too, so that may not be an acceptable solution.

  8. #8
    2 Star Lounger
    Join Date
    Oct 2007
    Posts
    172
    Thanks
    0
    Thanked 2 Times in 1 Post

    Re: Adding Shapes to Footers (Word 2003 VB)

    ok thanks. I think its never going to be perfect. My aim is to help people with my macros, not restrict them. For the user's part of the bargain, I guess they have to understand the macros won't be perfect if they mess about and don't do what they're supposed to.

    I think my current solution is acceptable and works unless they start manipulating the images manually. If they go down that road, then what do they expect right? :-)

  9. #9
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Adding Shapes to Footers (Word 2003 VB)

    I would use the AlternativeText property for this. It is intended to display in browsers which have images disabled, so is quite a sensible value to set in case you ever use this document as a web page. You can set the same value on every instance of the logo and it is simple to test for it.

    StuartR

  10. #10
    2 Star Lounger
    Join Date
    Oct 2007
    Posts
    172
    Thanks
    0
    Thanked 2 Times in 1 Post

    Re: Adding Shapes to Footers (Word 2003 VB)

    good tip. Thanks. It would make my code only slightly better in that it would get rid of the need for these crappy random number generated image names!

  11. #11
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,054
    Thanks
    2
    Thanked 417 Times in 346 Posts

    Re: Adding Shapes to Footers (Word 2003 VB)

    Hi Dom,
    <hr>the "fixed" logo appears in every footer<hr>
    That shouldn't be a problem - simply name each logo sequentially (eg Logo1, Logo2 and Logo3), then use Instr to test whether the shape name contains 'Logo'.
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  12. #12
    2 Star Lounger
    Join Date
    Oct 2007
    Posts
    172
    Thanks
    0
    Thanked 2 Times in 1 Post

    Re: Adding Shapes to Footers (Word 2003 VB)

    Hi Macropod,

    thanks for the suggestion. I am now going to change the code to use the "Alternative Text" property of the fixed logos, and then use a loop to delete all footer logos that don't have that fixed logo Alternative Text.

    should be a clean-ish solution!

    cheers
    Dom

Posting Permissions

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