osx - excel macro search for word and copy sentence -


I hope someone can help me with this problem.

I have two documents, one word and one excel is a list of items in the word file, for example:

title subtitles

  1 Name Address: Phone Number: 2. Name Address: Phone Number: 3. Name Address: Phone Number:    

In my Excel file There is a list of words in the nearest column D, what to do, take the word from column D, search for it in the word document, and then from "address" to "." For, copy the column C (i.e., from one cell to the left), and then after the "phone number:" "." And put it in column B.

One of those parts, which I can not wrap my head, is going from the next set, name, address and phone number to the next set.

Can anyone help me with a macro how to do this?

I thought it in its detail:

  Sub word search () 'Purpose: "title" and "address" if they both appear in the form of dim rng1 Range dim Rng2 range in the form of a string set in the form of strheadText as rng1 = ActiveDocument.Range if rng1.Find.Execute (FindText: = "Example:") set rng2 = ActiveDocument.Range (rng1.End, ActiveDocument.Range .End) if rng2.Find.Execute (FindText: = ".") Then strTheText = ActiveDocument.Range (rng1.End, rng2.Start). Text MsgBox strTtext end if end if ending sub    

As an example, given below For the excel Excel code catalog.doc is parsed as an Excel file, parsing RegExp with text, through contacts, and it's the dictionary , then gives the end through the D2: D10 cells, the correct data for the matched names is C and B < / Office> column MS Office 2003, winn Dosage tested in 7 HB

  Options Clear sub GetFromWord () Add 'Tools - Reference - Add': Microsoft Word 11.0 Object Library 'Microsoft VBScript Regular Expression 5.5' Microsoft scripting runtime dim strCont After the scripting.Dictionary dim objMatch as the range with the new word as the IMatch2 dim objElt. Application Document. Open thisWorkbook.Path & amp; With "\ Catalog.doc" .ActiveDocument.Range .WholeStory strCont =. End with end Finish with set objCatalog = New scripting with new RegExp.disk.pattern = "\ D + \. [\ T] * ([^ \ \ \ \] * s * Address: [\ t] * ( [^ \ N \ r] *) \ s * phone number: [\ t] * ([^ \ n \ r] *) \ s * "Global = True .MultiLine = True. For each objMatch, IgnoreCase = True .Execute (strCont) objcatalog.Add objMatch.SubMatches (0), array (objMatch.SubMatches (1), objMatch.SubMatches (2)) Next End with each objElt range ("D2: D10 ") objElt objCatalog.Exists (. (1, 1).) .offet (0, -1) = objatalog (. (1, 1). Value (0). Offset (0, -2) = objatalog (1, 1) value. (1) End And End End And End And End Sub   

Note, that there is an error in duplicated contacts in the word, no additional check Not implemented.

UPD: with initial binding In case of any problem, you have late binding CreateObject (ProgID) as follows, but this is not the best practice in VBA:

  Option to get clear sub-WordWindBBind ( ) With the String slow object as obsolete stroke, ObjMatch, objElt, as an object with CreateObject ("Word.Application"). Open the Document ThisWorkbook.Path & "\ Catalog.docx" .ActiveDocument.Range .WholeStory strCont =. End with end End with objcatalog = SetObject ("Scripting.Dictionary") set with SetObject ("VBScript.RegExp"). Pattern = "\ d + \". [\ T] * ([^ \ n \ r] *) \ s * Address: [\ t] * ([^ \ n \ r] *) \ s * Phone number: [\ t] * ([^ \ N \ r] *) \ s * ". Global = True .MultiLine = True .EgnoreCase = True in each objMatch.excute (stront) objcatalog.Add objMatch.SubMatches (0), Array (objMatch.SubMatches (1), ObjMatch Submachts (0) -1) ObjCent.exists (. (1, 1).) Then obsolete (0, -1) = Objcatalog (. Cells) in each objElt range ("D2: D10"). (1, 1). Value (0) .Offset (0, -2) = objatalog (. (1, 1). Value) (1) with end and end and end and end    

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -