You're a Newbie and jumping into the deep end! Word isn't laid out like Excel. Instead of nice, neat rows and columns, it has one huge block of text,broken apart by "carriage returns".Ok, sometimes it's broken up as paragraphs... Still, when working with a Word document, you basically read the whole thing into a variable and split it up based on the line feeds. I created a function that I passed the name of a Word document (with path) It opens the Word document, then has to wait for Windows to set the "focus" to the Word Application window.In my case, I loaded the entire document into an array called "TxtArray".Then looped through the array, looking for a "Part Number" and "Effective Date". take a look at what I've done and see if you can make it work for you:
Function GetWordData1(WordFile) Dim i, DocRange, PrtNo Dim fso, f, PartPos Dim EffDate, EffPos If (WordFile <> "") Then Set fso = CreateObject("Scripting.FileSystemObject") If fso.fileexists(WordFile) Then '-------------------------------------------------------------- Application.StatusBar = "Opening " & WordFile wrd.Documents.Open WordFile '-------------------------------------------------------------- Application.StatusBar = "Setting focus to Word" Set wrd = GetObject(, "Word.Application") Application.StatusBar = "Waiting" Application.Wait (Now + TimeValue("0:00:03")) '-------------------------------------------------------------- Err.Clear On Error Resume Next Application.StatusBar = "Obtaining DocRange" Set DocRange = ActiveDocument.Range(Start:=0, End:=0) If (Err.Number <> 0) Then GetWordData = "" Application.StatusBar = Err.Number & ": " & Err.Description Exit Function End If On Error GoTo 0 Application.StatusBar = "Copying Data to Array" DocRange.wholestory TxtArray = Split(DocRange.Text, Chr(13)) For i = 0 To UBound(TxtArray) If (InStr(1, UCase(TxtArray(i)), "PART NUMBER") > 0) Then PartPos = InStr(1, UCase(TxtArray(i)), "PART NUMBER") EffPos = InStr(1, UCase(TxtArray(i)), "EFFECTIVE DATE") PrtNo = Replace(Replace(Mid(TxtArray(i), InStr(1, UCase(TxtArray(i)), "PART NUMBER") + 12, 60), " ", ""), Chr(9), "") If EffPos > 0 And PartPos > 0 Then EffDate = EffDate = Replace(Replace(Mid(TxtArray(i), EffPos + 15, PartPos - EffPos - 15), Chr(9), ""), " ", "") If (Not IsNumeric(Right(EffDate, 1))) Then EffDate = Left(EffDate, Len(EffDate) - 1) End If Exit For End If Next i Set wrd = GetObject(, "Word.Application") wrd.Documents.Close GetWordData = PrtNo End If End If Application.StatusBar = False End Function Paul----------------------------------------- “Do all the good you can, By all the means you can, In all the ways you can, In all the places you can, At all the times you can, To all the people you can, As long as ever you can.” - John Wesley ----------------------------------------- From: Nihal k <nihalid...@gmail.com> To: MS EXCEL AND VBA MACROS <excel-macros@googlegroups.com> Sent: Friday, July 24, 2015 1:20 AM Subject: $$Excel-Macros$$ How to get specific text from first page of word Document using macro vba? Hi all,I am newbie to Excel. I want to get specific data from path (say C:\Test\Hello.doc") where first page of the word document contains " Hello = 123" & "Good morning =234". I want to fetch "Hello =123" to excel worksheet using macro vba. Can anybody help me please. -- Are you =EXP(E:RT) or =NOT(EXP(E:RT)) in Excel? And do you wanna be? It’s =TIME(2,DO:IT,N:OW) ! Join official Facebook page of this forum @ https://www.facebook.com/discussexcel FORUM RULES 1) Use concise, accurate thread titles. Poor thread titles, like Please Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will not get quick attention or may not be answered. 2) Don't post a question in the thread of another member. 3) Don't post questions regarding breaking or bypassing any security measure. 4) Acknowledge the responses you receive, good or bad. 5) Jobs posting is not allowed. 6) Sharing copyrighted material and their links is not allowed. NOTE : Don't ever post confidential data in a workbook. Forum owners and members are not responsible for any loss. --- You received this message because you are subscribed to the Google Groups "MS EXCEL AND VBA MACROS" group. To unsubscribe from this group and stop receiving emails from it, send an email to excel-macros+unsubscr...@googlegroups.com. To post to this group, send email to excel-macros@googlegroups.com. Visit this group at http://groups.google.com/group/excel-macros. For more options, visit https://groups.google.com/d/optout. -- Are you =EXP(E:RT) or =NOT(EXP(E:RT)) in Excel? And do you wanna be? It’s =TIME(2,DO:IT,N:OW) ! Join official Facebook page of this forum @ https://www.facebook.com/discussexcel FORUM RULES 1) Use concise, accurate thread titles. Poor thread titles, like Please Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will not get quick attention or may not be answered. 2) Don't post a question in the thread of another member. 3) Don't post questions regarding breaking or bypassing any security measure. 4) Acknowledge the responses you receive, good or bad. 5) Jobs posting is not allowed. 6) Sharing copyrighted material and their links is not allowed. NOTE : Don't ever post confidential data in a workbook. Forum owners and members are not responsible for any loss. --- You received this message because you are subscribed to the Google Groups "MS EXCEL AND VBA MACROS" group. To unsubscribe from this group and stop receiving emails from it, send an email to excel-macros+unsubscr...@googlegroups.com. To post to this group, send email to excel-macros@googlegroups.com. Visit this group at http://groups.google.com/group/excel-macros. For more options, visit https://groups.google.com/d/optout.