How to Use VBA to Read a Microsoft Word Document

Written by jaime avelar
  • Share
  • Tweet
  • Share
  • Pin
  • Email
How to Use VBA to Read a Microsoft Word Document
In a few steps you can set up your computer to read a Word document using VBA. (code image by Charles Taylor from

Microsoft Word is a word processor program used to create and format documents. Visual Basic for Applications (VBA) is commonly used to automate repetitive tasks among Microsoft Office applications such as Word, Excel and Access. In a few steps you can write a small sub to read a Word document in VBA.

Skill level:

Other People Are Reading


  1. 1

    Open Microsoft Excel 2007. Click on the "Developer" tab and select "Visual Basic." Type "Sub readWordDocuemnt()" and press "Enter" to create a new sub.

  2. 2

    Type the following to declare your variables:

    Dim word Application As Word.Application

    Dim word Document As Word.Document

    Dim pText As String

    Dim pRange As Word.Range

    Dim pCount As Long

    Dim rXLRow As Long

  3. 3

    Type the following to create a new Excel workbook and open the Word document to be read:


    Set word Application = CreateObject("Word.Application")

    Set word Document = wordApplication.Documents.Open("C:\Text in Word.doc")

  4. 4

    Type the following to loop through the paragraphs in the Word document and add them to the new Excel workbook:

    rXLRow = 2

    With word Document

    For pCount = 1 To .Paragraphs.Count

    Set pRange = .Range(Start:=.Paragraphs(pCount).Range.Start, _


    pText = pRange.Text

    ActiveSheet.Range("A" & rXLRow).Formula = pText

    rXLRow = rXLRow + 1

    Next pCount


    End With

  5. 5

    Type the following to save the new workbook, quit Word and clear variables:


    Set word Document = Nothin:

    Set word Application = Nothing

    ActiveWorkbook.Saved = True

  6. 6

    Execute the sub.

Don't Miss

  • All types
  • Articles
  • Slideshows
  • Videos
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the site, you consent to the use of cookies. For more information, please see our Cookie policy.