Results 1 to 8 of 8
  1. #1
    3 Star Lounger
    Join Date
    Nov 2001
    Posts
    342
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Copy contents of variable to document (Word 2000 SR-1)

    I know how to copy selected text into a variable, but how do I place the contents of a variable into a document?

    I am using the on error method to capture all instances where an error may occur into a variable called 'gotcha'. I then want to 'paste' the contents of my variable, 'gotcha' into a fresh document so I can print it out and analyse the errors. How do I do this?

    Thanks in advance.

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

    Re: Copy contents of variable to document (Word 2000 SR-1)

    Dim docError As Document

    Set docError = Documents.Add
    docError.Content.InsertAfter gotcha


    StuartR

  3. #3
    2 Star Lounger
    Join Date
    Feb 2001
    Location
    Brussels, Brussel, Belgium
    Posts
    159
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Copy contents of variable to document (Word 2000 SR-1)

    hi Ted,

    for a text only variable you could use
    documents.add.range.text=gotcha

    however, if the variable' content is small, you could print it to the immediate window in the VBE (debug.print gotcha) or even hover over the variable name while in debug mode to view its content in a tooltip that will appear.

  4. #4
    2 Star Lounger
    Join Date
    Jul 2003
    Location
    Park City, Utah
    Posts
    189
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Copy contents of variable to document (Word 2000 SR-1)

    What is the right way to insert the variable into the current document, rather than open a new document?

  5. #5
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Los Angeles Area, California, USA
    Posts
    7,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Copy contents of variable to document (Word 2000 SR-1)

    I can't answer your question directly, but FYI, Chris Woodman makes a ShortOrg.dot that not only enables copying shortcut keys using the Organizer, but adds a command on the File menu to add, delete, or modify document variables easily.
    Cheers,

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

    Re: Copy contents of variable to document (Word 2000 SR-1)

    Something like

    With ActiveDocument.Content
    .InsertParagraphAfter
    .InsertAfter gotcha
    End With

  7. #7
    2 Star Lounger
    Join Date
    Feb 2001
    Location
    Brussels, Brussel, Belgium
    Posts
    159
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Copy contents of variable to document (Word 2000 SR-1)

    hi Jeanie,

    maybe you're overgeneralising your question a bit here. if you have an existing document, then you probably want to insert the variable (we are talking about vba variables, right?) at a particular place. the most common technique to achieve this, is to use bookmarks.
    you first determine where you want to go the variable and then at that place you insert a bookmark, using word's menu insert->bookmark and call it for instance myvargoeshere. in the code later you reference this bookmark to insert the content of the variable at that exact predetermined place :

    activedocument.bookmarks("myvargoeshere").range.te xt=gotcha

    for more information, have a look at the mvp word vba faq

    don't hesitate to post back if you have more questions.

    hth

  8. #8
    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: Copy contents of variable to document (Word 2000 SR-1)

    > What is the right way to insert the variable into the current document, rather than open a new document?

    This probably depends on your circumstances. The easiest and most intuitive is to position the insertion point where you want the new text inserted and, if it's plain text, use Selection.TypeText following by your variable or literal text. If it's "rich text" containing formatting, it's harder. Most developers seem to prefer to convert Selection-based code to Range-based code because, arguably, it is faster. But if you can get it working with the Selection object first, there's time to migrate later. <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

Posting Permissions

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