|
-
Nov 14th, 2007, 08:07 AM
#1
Thread Starter
New Member
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.
-
Nov 14th, 2007, 08:13 AM
#2
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Nov 14th, 2007, 08:21 AM
#3
Thread Starter
New Member
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.
-
Nov 14th, 2007, 09:00 AM
#4
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Nov 15th, 2007, 04:18 AM
#5
Re: Word [2003]
you can try like this
vb Code:
Dim d As Document, somefolder As String, myfile As String, myfooter As String
Dim myheader As String
somefolder = Environ("userprofile") & "\My Documents\"
myfile = Dir(somefolder & "*.doc")
Do While Len(myfile) > 0
Set d = Documents.Open(somefolder & myfile)
myheader = d.Sections(1).Headers(1).Range.Text
Select Case Left(myheader, Len(myheader) - 1)
myfooter = "some address"
myfooter = "someother address"
Case Else
myfooter = "generic address for other cases"
End Select
d.Sections(1).Footers(1).Range.Text = myfooter
myfile = Dir
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|