Send a suggestion!

We're building a brand new version of the site, and we'd love to hear your ideas

Members

Technology Zones

IBM Learning Center

Articles

Hosted By

MaximumASP

Info

hello need help in macro

Last post 05-15-2008 9:08 AM by Jugatsu. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 05-13-2008 11:00 AM

    • matrixpro
    • Not Ranked
    • Joined on 05-13-2008
    • Israel
    • New Member
    • Points 20

    hello need help in macro


    i dont have clue in VB or programing i need to create small macro
    that will change my company addres in old word file i need him to look in my files
    dir and check what file dont have the right address any idea how can i newb can do it
    btw the line is in lower header

    thx who ever help me

    • Post Points: 10
  • Advertisement

    • Red Gate Software

    Advertisement

    Want to boost your .NET application performance?

    Some developers always seem to write efficient and lightening-fast code. What is their secret? It’s ANTS Profiler. “We improved the performance of the application up to 10 times” Dan Ports, Intrigma.

    Try it for yourself now.

  • 05-13-2008 2:54 PM In reply to

    • Jugatsu
    • Top 500 Contributor
    • Joined on 02-15-2006
    • Addicted Member
    • Points 485

    Re: hello need help in macro

    Hi,

    Open a Word document, Click Tools - Macros - Visual Basic Editor
    Double click This document on the left.
    Paste in the code below
    Change the Diectory Location, OldAddress & NewAddress
    Then Run the code - I would try it out on test files first.

    Private Sub Main()
        Dim strPath As String
        Dim strFile As String
        Dim sFooter As String
        Dim objWord As Word.Application
        Dim objDocContent As Word.Range

        Set objWord = New Word.Application

        ' This is the Directory Location
        strPath = "C:\Test\"
       
        ' Look for Word Documents only
        strFile = Dir(strPath & "*.doc", vbDirectory)
       
        While strFile <> ""

            ' Open the Document
            objWord.Documents.Open strPath & strFile

            ' Get the contents
            Set objDocContent = objWord.ActiveDocument.Content

            ' Get the Footnote
            sFooter = objDocContent.Sections(1).Footers(Word.WdHeaderFooterIndex.wdHeaderFooterPrimary).Range.Text
           
            If InStr(1, sFooter, "OldAddress") Then
                 sFooter = Replace(sFooter, "OldAddress", "NewAddress")
                 objDocContent.Sections(1).Footers(Word.WdHeaderFooterIndex.wdHeaderFooterPrimary).Range.Text = sFooter
                 objWord.Documents.Save
            End If
           
            ' Close the Document
            objWord.Documents.Close

            ' Get the next Document
            strFile = Dir
        Wend
          
        ' Quit Word
        objWord.Quit
        ' Destroy the object
        Set objWord = Nothing

    End Sub

    • Post Points: 10
  • 05-13-2008 3:19 PM In reply to

    • matrixpro
    • Not Ranked
    • Joined on 05-13-2008
    • Israel
    • New Member
    • Points 20

    Re: hello need help in macro

    ffirst i most say thx for replay Jugatsu

    i did what u sad but noting happenad i think

    cuz it part of the title of the doc file or cuz its in hebrew

    cuz i didnt find any problem

    any idea m8 ? 

     

     

     

    • Post Points: 10
  • 05-15-2008 9:08 AM In reply to

    • Jugatsu
    • Top 500 Contributor
    • Joined on 02-15-2006
    • Addicted Member
    • Points 485

    Re: hello need help in macro

    A quick way of checking is to put in message boxes (popups) with the details for each step
    This way you can debug the program to check what is the issue.
    Do not have many file in the Directory or you will get lots of pop ups...


            ' Open the Document
            objWord.Documents.Open strPath & strFile
            msgbox strPath & strFile ' Name of the file

            ' Get the contents
            Set objDocContent = objWord.ActiveDocument.Content
            msgbox objDocContent ' The text with in the doument

            ' Get the Footnote
            sFooter = objDocContent.Sections(1).Footers(Word.WdHeaderFooterIndex.wdHeaderFooterPrimary).Range.Text
            msgbox sFooter ' The footer of the doument

    • Post Points: 5
Page 1 of 1 (4 items)