Results 1 to 5 of 5

Thread: Word [2003]

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2007
    Posts
    2

    Word [2003]

    hi, I need to search for an email addresses within the header of a number of documents and then replace the contents of the footer dependant upon the email address.

    for instance if a document has [email protected] then i will replace the footer address with address A. If the email address is [email protected] then it will have address B.

    There are probably 10 different email addresses and a few thousand word documents.

    What I would like to do is to have it run as an auto macro make the change and save/close the document.I can then select a number od documents at once.

    Any help - Sorry I am not a developer.

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Word [2003]

    Welcome to the Forums.

    One of the easiest ways to get a start with programming for most aoffice apps is to record a macro of your task and view the generated module code.

    http://vbforums.com/showthread.php?t=402032

    There is a .Find function that also has a .ReplaceText property that you can specify.

    Generate some basic code and we can modify it to your specific needs.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    New Member
    Join Date
    Nov 2007
    Posts
    2

    Smile Re: Word [2003]

    Thank you for your comments.

    I have looked at the .find and .replace functions but cannot see a way to finding one thing in a document but replacing something else.

    I cannot just replace the footer addresses as they are currently either missing or the same. I therefore need to categorise these by the email address and apply the appropiate postal address in the footer.

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Word [2003]

    Hmm, these situations are always "fun"

    I guess you would have to do a loop passing each of the 10 email addresses and if none are found then write out the default addy and postal info.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  5. #5
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Word [2003]

    you can try like this
    vb Code:
    1. Dim d As Document, somefolder As String, myfile As String, myfooter As String
    2. Dim myheader As String
    3. somefolder = Environ("userprofile") & "\My Documents\"
    4. myfile = Dir(somefolder & "*.doc")
    5. Do While Len(myfile) > 0
    6.     Set d = Documents.Open(somefolder & myfile)
    7.     myheader = d.Sections(1).Headers(1).Range.Text
    8.     Select Case Left(myheader, Len(myheader) - 1)
    9.         Case ("[email protected]")
    10.             myfooter = "some address"
    11.         Case "[email protected]"
    12.             myfooter = "someother address"
    13.         Case Else
    14.             myfooter = "generic address for other cases"
    15.     End Select
    16.     d.Sections(1).Footers(1).Range.Text = myfooter
    17.     myfile = Dir
    18. Loop
    this look for the files in somefolder, (my documents, in the code), you can expand the select case for all your addresses, if the headers or footers contain additional text you will have to modify the routine to find or add the bits you want
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

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