Results 1 to 7 of 7

Thread: MS Word Macro Help (VB Code)

Threaded View

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2005
    Posts
    8

    Question 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:
    1. Sub StripBillingInfo()
    2.     On Error GoTo errorhandler
    3.     'set up variables
    4.     Dim SectionNumber As Integer
    5.     Dim RangeToSpike As Range
    6.     Dim AccumulatedText As String
    7.    
    8.     'loop through sections
    9.     For SectionNumber = 1 To ActiveDocument.Sections.Count
    10.         'mark the first paragraph of the section, less the paragraph mark
    11.         Set RangeToSpike = ActiveDocument.Sections(SectionNumber).Range.Paragraphs.First.Range
    12.         RangeToSpike.MoveEnd wdCharacter, -1
    13.         If RangeToSpike.Start = RangeToSpike.End Then GoTo GetNextSection
    14.         If Mid(RangeToSpike.Text, 1, 3) <> "%%%" Then GoTo GetNextSection
    15.         'add the first paragraph to the spike, then delete it
    16.         RangeToSpike.MoveStart wdCharacter, 3
    17.         AccumulatedText = AccumulatedText & RangeToSpike.Text & vbCr
    18.         ActiveDocument.Sections(SectionNumber).Range.Paragraphs.First.Range.Delete
    19. GetNextSection:
    20.     Next SectionNumber
    21.     'create a new document and dump the spike into it
    22.     Documents.Open FileName:="e:\billing.txt", ConfirmConversions:=False, Format:=wdOpenFormatText
    23.     Selection.EndKey wdStory
    24.     If Selection.Paragraphs.First.Range.Characters.Count > 1 Then
    25.         Selection.InsertParagraph
    26.         Selection.EndKey wdStory
    27.     End If
    28.     Selection.TypeText AccumulatedText
    29.     ActiveDocument.Close wdSaveChanges
    30. errorhandler:
    31. 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
  •  



Click Here to Expand Forum to Full Width