简体   繁体   中英

How to pull specific data/text from Word to specific cells in Excel?

I am a newbie to Excel VBA. I need to accomplish an important automation task using Excel VBA. It requires pulling specific data/text from Word file to Excel sheet. Please see attached sample files.

Excel File

Word File

The highlighted date and each date under it in Word file needs to be extracted and put into the 'PO issue date' column in Excel first sheet. Similarly, each part number (highlighted) in word file needs to be put it into the 'Funai Part No' column.

Similarly, the quantity in word file under 'TOTAL' needs to be put into the 'Required Qty' column and PO number in word file (Lastrow end value - 70525003) needs to be put into the 'PO Number' column. This PO number will be similar for all other dates as well entered in Excel.

Can you add Bookmarks to Word, and run the script below?

Sub PushToWord()

Dim objWord As New Word.Application
Dim doc As Word.Document
Dim bkmk As Word.Bookmark
sWdFileName = Application.GetOpenFilename(, , , , False)
Set doc = objWord.Documents.Open(sWdFileName)
On Error Resume Next

    Range("B1").Value = ActiveDocument.Variables("BrokerFirstName").Value
    Range("B2").Value = ActiveDocument.Variables("BrokerLastName").Value
    ActiveDocument.Fields.Update

On Error Resume Next
objWord.Visible = True

End Sub

That should give you what you want.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM