Results 1 to 5 of 5
  1. #1
    degras is offline Advanced Beginner
    Windows 7 Access 2007
    Join Date
    Nov 2010
    Posts
    72

    Import Word document using VBA


    How is it possible to import a Word document, one line at a time using VBA? I am only interested in the raw text, so converting the file first may be an option. I will need to scan the line / variable for certain key words.

  2. #2
    kennejd is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Mar 2011
    Posts
    188
    Word won't work....but if you could save the file to .txt, you could import that.

  3. #3
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    Quote Originally Posted by kennejd View Post
    Word won't work
    that's not true at all. of course you can import word doc text line by line, but converting to a .txt would be much simpler, primarily because after that, you can stream the entire file right on in using I/O.

  4. #4
    evander is offline Competent Performer
    Windows 7 Access 2003
    Join Date
    Apr 2010
    Location
    Philippines
    Posts
    206
    My answer may be a bit inconsistent with the purpose of this site, but here goes... I think it would be easier if you simply imported the Word file into an Excel spreadsheet one line at a time using VBA. After such process, you could import the Excel file into an Access database without any code at all.

    In summary, you select a line of text inside Word, and throw it onto an Excel cell, then loop through this process till the end of the document.

    Code:
    Private Sub ExportExcel
         Do Until Selection.Information(wdActiveEndPageNumber) < 1000
              Word.Selection.HomeKey Unit:=wdLine, Extend:=wdMove
              Word.Selection.EndKey Unit:=wdLine, Extend:=wdExtend
              Excel.ActiveCell.Value = Selection.Text
              DoEvents
         Loop
    End Sub
    You can also include other complex codes, such as creating an Excel object before manipulating it, creating a string that will temporarily hold the value of your current selection so that you can manipulate it using a loop, and so on.

    Hope this helps. Good luck.

    Jan

  5. #5
    degras is offline Advanced Beginner
    Windows 7 Access 2007
    Join Date
    Nov 2010
    Posts
    72
    Thanks. I'll save the files as text and then import them.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Open a word document from access
    By natalia in forum Programming
    Replies: 1
    Last Post: 10-13-2010, 08:04 AM
  2. Replies: 7
    Last Post: 08-31-2010, 12:15 PM
  3. Replies: 5
    Last Post: 07-16-2010, 10:12 AM
  4. Replies: 0
    Last Post: 01-18-2009, 09:18 PM
  5. Word document INTO Access form
    By jonathonhicks in forum Forms
    Replies: 0
    Last Post: 04-30-2007, 05:59 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums