locked
Word 2007 VBA: Assigning the entire text of a document to a variable RRS feed

  • Question

  • I want to be able to assign the entire document (e.g., c:\wordforms\test_document.doc) to a variable so that I can manipulate it.

     

    How is that done?

    Wednesday, September 22, 2010 9:15 PM

Answers

  • Declare a variable

    strEntireDoc As String

    give the variable the value

    strEntireDoc = ActiveDocument.Range.Text

     

    Assuming c:\wordforms\test_document.doc is both open and the ActiveDocument.  if it is open but NOT the ActiveDocument, then:

    strEntireDoc = Documents(test_document.doc)

    However, you can most likely manipulate whatever you want without actually putting the entire document into a variable.  In fact, I would bet on it.


    Gerry
    • Marked as answer by Jennifer Zhan Thursday, September 30, 2010 7:41 AM
    Wednesday, September 22, 2010 9:29 PM

All replies

  • Declare a variable

    strEntireDoc As String

    give the variable the value

    strEntireDoc = ActiveDocument.Range.Text

     

    Assuming c:\wordforms\test_document.doc is both open and the ActiveDocument.  if it is open but NOT the ActiveDocument, then:

    strEntireDoc = Documents(test_document.doc)

    However, you can most likely manipulate whatever you want without actually putting the entire document into a variable.  In fact, I would bet on it.


    Gerry
    • Marked as answer by Jennifer Zhan Thursday, September 30, 2010 7:41 AM
    Wednesday, September 22, 2010 9:29 PM
  • Thanks.

    This is fine but I should have clarified: the text of the document I want is neither open nor the ActiveDocument.

    Wednesday, September 22, 2010 10:04 PM
  • You will have to open it.

    -- Hope this helps.

    Doug Robbins - Word MVP,
    dkr[atsymbol]mvps[dot]org
    Posted via the Community Bridge

    "LA Lawyer" wrote in message news:7786787d-e5d8-42bc-a972-0a33ea5e9b33@communitybridge.codeplex.com...

    Thanks.

    This is fine but I should have clarified: the text of the document I want is neither open nor the ActiveDocument.


    Doug Robbins - Word MVP dkr[atsymbol]mvps[dot]org
    Wednesday, September 22, 2010 11:16 PM