none
Word document content is replaced by the content of another Word document that is open in the background RRS feed

  • Question

  • Hi,

    I have recently encountered word automation problem.

    If I have an open document in a background and I'm trying to create new one using

    a = wordobj.Documents.add(str_template)

    wordobj.Documents(a).Activate

    With .ActiveDocument

         .SaveAs full_pass & "." & WordExtention

    End With

    WordExtention - depending on word version client has on his computer

    The result is insane the new document gets background document content and the background document is over
    righted
    by new document content.

    I have heard about this behavior on word 2003 having outlook 2003 use word as editor option turned on, the result was email content replacing word document content, but I have office 2007 on the client side.

    Any help will be appreciated.

    Leon

    Thursday, October 17, 2013 2:16 PM

Answers

  • Hi Leon

    The simple answer is "don't do that", and indeed, there is no reason for you to do that. You should not need ActiveDocument. Instead, use

         With a
             .SaveAs

    ActiveDocument is like Selection, you can never really be sure what it is you're working with unless you run a lot of checks. As long as you've declared and instantiated a Word.Document object (a), use that - without fail!


    Cindy Meister, VSTO/Word MVP, my blog

    • Marked as answer by Masig Wednesday, October 23, 2013 11:17 AM
    Thursday, October 17, 2013 4:34 PM
    Moderator