Results 1 to 3 of 3

Thread: Microsoft word macro

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2005
    Posts
    3

    Microsoft word macro

    I'm trying to figure out how to do the following:
    I need to write a Microsoft word macro in Visual Basic which will search through a document and every time it finds a certain word it replaces it with a picture. The picture that it needs to replace it with is determined by a text file. I figured the best way to do this would be to open the text file as an input file and create a hash table. The text file is set up basically like this exept its much larger.
    A pic1
    b pic2
    c pic3

    I have the search function which finds the word inside the word document figured out, the problem that I'm having is with reading in the file that contains the key and value and creating the hash table and getting the value out of it. I've tried looking for some code examples that will help and am having trouble finding any. Any help is much appreciated.

  2. #2

    Thread Starter
    New Member
    Join Date
    Sep 2005
    Posts
    3

    Re: Microsoft word macro

    Figured that I'd put up what I have so far. I haven't coded in visual basic in about 8 years, and I don't ever remember writing macros in microsoft word so I'm not sure how to do everythign I want to and am having trouble finding anything that helps figure everything out. This is what I have so far...


    Dim number As Integer
    Dim signatures As String
    Dim employee_signature_bmp As String
    Dim employee_find As String
    Dim case_name As String
    Set employee_signatures = CreateObject("scripting.dictionary")
    number = 1

    With Selection.Find
    .Text = "zqx"
    .Replacement.Text = " "
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchAllWordForms = False
    .MatchSoundsLike = False
    .MatchWildcards = True
    End With

    Open "C:\WINDOWS\Desktop\ERIC'S\employeeSignatures.txt" For Input As number
    Do While Not EOF(number)
    Line Input #number, signatures$
    y = Len(signatures)
    case_name = Trim(Mid(signatures, 1, 5))
    signature_to_add = Trim(Mid(signatures, 9, y))
    employee_signatures.Add case_name, signature_to_add
    Loop
    Close #number
    Close number

    Do While Selection.Find.Execute() = True
    Selection.EndKey unit = wdLine, Extend:=wdExtend
    case_name = Trim(Mid(Selection.Text, 4, 5))
    If employee_signatures.Exists(case_name) = True Then
    employee_signature_bmp = employee_signature.Item(case_name)
    employee_signature_bmp = ("C:\windows\desktop\eric's\") + employee_signature_bmp
    Selection.InlineShapes.AddPicture FileName = employee_signature_bmp, linktofile = False, savewithdocument:=True
    Else
    Selection.EndKey unit = wdLine, Extend:=wdMove
    Selection.Delete unit:=wdCharacter, Count:=1
    Selection.Delete unit:=wdCharacter, Count:=1
    Selection.Delete unit:=wdCharacter, Count:=1
    End If
    Loop
    Selection.HomeKey unit:=wdStory
    End Sub

    any help is much appreciated

  3. #3

    Thread Starter
    New Member
    Join Date
    Sep 2005
    Posts
    3

    Re: Microsoft word macro

    I figured it out...sorry for all the posts

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