Results 1 to 6 of 6
  1. #1
    2 Star Lounger
    Join Date
    Jan 2004
    Location
    Mount Prospect, Illinois
    Posts
    142
    Thanks
    0
    Thanked 0 Times in 0 Posts

    VBA style delete always deletes from active doc (2003)

    I have a style-cleanup routine that instead of pasting directly into my doc, it pastes in a newly-created doc, deletes some styles specified by the user, maps any text in "Normal" to a different style (which handles the styles just deleted), and then copies and pastes whats left into my doc.

    so it's something like:

    set oDoc = Documents.Add(Visible:=False)
    oDoc.Content.Paste
    oDoc.Styles("Bogus").Delete

    At this point, the doc I copied from has Styles("Bogus") now gone!!!

    I've checked very carefully to ensure that it's really the "quarantine" doc I'm operating on, but the style stays there, and deletes from the active document.

    This is frustrating, dangerous, and just, plain, wrong.
    Any clues or ideas? Do I have to have an active doc to delete styles from it?

  2. #2
    Gold Lounger
    Join Date
    Feb 2004
    Location
    Cape Town, RSA
    Posts
    3,444
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: VBA style delete always deletes from active doc (2003)

    I speak under correction, but should you not re-activate (or set a reference to) the original doc? If you add a document (even if it is not visible) will this not become the active doc and all remaining actions be applied to that doc.?

    After adding a doc, try re-activating the original and then delete the style.

    Just a though as I am not a guru with word code... <img src=/S/smile.gif border=0 alt=smile width=15 height=15>
    Regards,
    Rudi

  3. #3
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts

    Re: VBA style delete always deletes from active do

    Looking at your code, I would agree that this is a problem and can understand your frustration.

    Do you get the same result if you make the doc visible? Do you get the same problem if you step through the code (is it speed related)? If you added a save step after the paste does this force the correct action (possibly by allowing enough time to elapse so that Word doesn't get so confused)?
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  4. #4
    2 Star Lounger
    Join Date
    Jan 2004
    Location
    Mount Prospect, Illinois
    Posts
    142
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VBA style delete always deletes from active doc (2003)

    I did some more experimenting, and doing
    oDoc.Activate
    before deleting the style makes sure that it gets deleted from oDoc.
    And Rudi, yes, I did set a ref to the original active document, and after completion, oOrigDoc.Activate gets me back there.

    I didn't try making the invisible doc visible, but active did work.

    Still, it's a bug, a bad bug, but at least i found a way around it.

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

    Re: VBA style delete always deletes from active doc (2003)

    It's good to know this - it really is a nasty bug!

  6. #6
    2 Star Lounger
    Join Date
    Feb 2001
    Location
    Wellington, New Zealand
    Posts
    143
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: VBA style delete always deletes from active do

    Have you tried using the Organizer to delete the style as an alternative to activating the invisible document? Something like the following might work as expected, though I haven't tested it:

    Application.OrganizerDelete Source:=oDoc, Name:="Bogus", Object:=wdOrganizerObjectStyles

Posting Permissions

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