|
-
Feb 3rd, 2005, 09:08 AM
#1
Thread Starter
New Member
MS Word Macro Help (VB Code)
Hello all,
I am working on this vb word macro that strips a billing code(paragraph) from the top of a document and places it in a text file.
Here is an example of what the billing code looks like:
%%%«Today:06/03/90»,”«Matter ID»”,” TDLR”,«Matter type»,”preparing correspondence to «Addressee full name» regarding trademark renewal deadline approaching on «Parent event date:June 3, 199011», seeking instructions regarding same”,”«Mark:LIKE THIS»”,””,””
The problem is that the billing code is now going to be moved to the bottom of the document. The current macro is not coded to search through the whole document for the billing code, it just looks at the first paragraph.
Can someone help me adjust the following code so that it will search the entire document for the billing code instead of just the first paragraph.
Here is the vb code currently being used:
VB Code:
Sub StripBillingInfo()
On Error GoTo errorhandler
'set up variables
Dim SectionNumber As Integer
Dim RangeToSpike As Range
Dim AccumulatedText As String
'loop through sections
For SectionNumber = 1 To ActiveDocument.Sections.Count
'mark the first paragraph of the section, less the paragraph mark
Set RangeToSpike = ActiveDocument.Sections(SectionNumber).Range.Paragraphs.First.Range
RangeToSpike.MoveEnd wdCharacter, -1
If RangeToSpike.Start = RangeToSpike.End Then GoTo GetNextSection
If Mid(RangeToSpike.Text, 1, 3) <> "%%%" Then GoTo GetNextSection
'add the first paragraph to the spike, then delete it
RangeToSpike.MoveStart wdCharacter, 3
AccumulatedText = AccumulatedText & RangeToSpike.Text & vbCr
ActiveDocument.Sections(SectionNumber).Range.Paragraphs.First.Range.Delete
GetNextSection:
Next SectionNumber
'create a new document and dump the spike into it
Documents.Open FileName:="e:\billing.txt", ConfirmConversions:=False, Format:=wdOpenFormatText
Selection.EndKey wdStory
If Selection.Paragraphs.First.Range.Characters.Count > 1 Then
Selection.InsertParagraph
Selection.EndKey wdStory
End If
Selection.TypeText AccumulatedText
ActiveDocument.Close wdSaveChanges
errorhandler:
End Sub
Last edited by RobDog888; Feb 3rd, 2005 at 02:56 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|