Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

New and need help with Word Macro

Status
Not open for further replies.

k8277

Programmer
Jan 10, 2003
104
US
I am new to VBA programming and need a little help with a Word 97 macro. Here is a sample of my Word Document:

DATE: 9/13/02
PAGE: 1
TIME: 7:27:27
MEMBER NAME: AR770C
MEMBER TYPE: CLP
...
...


The excerpt above is found on the top of every page. I need to determine what the value of the MEMBER TYPE is. In the above example it is CLP. I would like the Macro to do the following:

Start at the first line of the document.
Read every line.
When you come to a new page, find the line that contains MEMBER TYPE
Determine the value of MEMBER TYPE
Store this value in a variable (temp)
If (temp=CLP)
Do this code
Else
Do this code
End If

Any help would be appreciated. Thanks in advance.
 
Hi k8277,

The easiest way to get started is to record a macro and look at the code. Making a few assumptions about your data here is what I would do.

Start off by recording a macro doing the following
[ul][li]Find (use <Ctrl><F> to get the dialog box) &quot;MEMBER TYPE:&quot;[/li][li]Close the dialog box[/li][li]Use <Ctrl><right arrow> to skip to the start of the string you want[/li][li]Use <Ctrl><Shift><right arrow> to block it up[/li][li]Now stop recording and look at the code.[/li][li]After it you can add your code ... If Selection = &quot;CLP&quot; (or whatever) Then etc. etc.[/li][/ul]That should get you through the first page. To repeat for other pages you need to find the start of each page first. As pagination is printer-dependent, I assume that you have manual page breaks in your document so time to record again. This time[ul][li]In the Find dialog box click on &quot;Special&quot; and select &quot;Manual Page Break&quot; to put &quot;^m&quot; in the &quot;Find What&quot; box[/li][li]When you have found it, stop recording and check out the code[/li][li]You are now at the top of the next page and can repeat what you have already done[/li][/ul]I hope that all makes sense and helps get you started.

Enjoy,
Tony
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top