Closed Thread
Results 1 to 4 of 4

Extract data from word document

Hybrid View

hme Extract data from word... 01-13-2008, 06:08 AM
royUK o set a reference to MS Word... 01-13-2008, 07:58 AM
hme thank you very much for your... 01-15-2008, 08:27 AM
shaluak Re: Extract data from word... 06-14-2011, 04:37 PM
  1. #1
    Registered User
    Join Date
    11-01-2004
    Posts
    37

    Extract data from word document

    Hi

    I am going to modify a macro to extract data from MS Word documents. I run below mentioned macro but in the beginning where there is :


    ('Set a reference (Tools - References) to the

    'Microsoft Word x.0 Object Library)

    I don’t know what should I do.

    And also I face error on:

    (Dim wdApp As Word.Application)

    May somebody help me?
    The complete macro is following.

    rgds
    hme



    Sub GetDataFromWord()
    
    'Set a reference (Tools - References) to the
    'Microsoft Word x.0 Object Library
    
    Dim wdApp As Word.Application
    Dim wdDoc As Word.Document
    Dim sFile As String
    Dim rInput As Range
    
    'Define row and column of data in table
    Const lROW As Long = 2
    Const lCOL As Long = 2
    
    'Specify file that contains table
    sFile = "C:\Documents and Settings\Hashemi\Desktop\Macro test\test.doc"
    
    'instantiate Word and open document
    Set wdApp = New Word.Application
    Set wdDoc = wdApp.Documents.Open(sFile)
    
    'define range where data goes
    Set rInput = Sheet1.Range("a1")
    
    'Copy value from table and paste to cell
    With wdDoc.Tables(1)
    .Cell(lROW, lCOL).Range.Copy
    rInput.PasteSpecial xlPasteValues
    End With
    
    wdDoc.Close False
    wdApp.Quit
    
    Set wdDoc = Nothing
    Set wdApp = Nothing
    
    End Sub
    Last edited by VBA Noob; 01-13-2008 at 06:19 AM.

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    o set a reference to MS Word you need to open the Visual basic editor (Alt+F11), then from the Tools menu select references. Then scroll down the list until you find "Microsoft Word 12.0 Object Library" and check the box. Note: the number refers to the version of word on your PC, so it might be a different number. Click OK & close the Dialog.

    Now try running the macro.

    Edit; the code runs with no error when the reference has been set
    Last edited by royUK; 01-13-2008 at 08:11 AM.
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Registered User
    Join Date
    11-01-2004
    Posts
    37
    thank you very much for your reply royUK

    It is working well

    may you help me to modify this macro to retrieve the line where there is "Subject" and copy this line and 2 line before and 2 line after this line to an excel worksheet (insted of retrieve the information from the table in word as it is in above macro) and do this for all word doc. in a specific folder.

    rgds
    hme

  4. #4
    Registered User
    Join Date
    06-13-2011
    Location
    Bangalore,india
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Extract data from word document

    Suppose the word contains the data not in a table format,instead line wise.

    eg.

    Serial Number
    2345678

    Abstract
    aaaaaaaaaaaaaaaa
    nnnnnnnnnnnnnnn

    date of publication
    21.03.2011

    then how to copy a serios of data in word format similiar to this in to excel using macros

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1