![]() |
![]() |
![]() |
|||||
![]() |
![]() |
![]() |
![]() |
![]() |
|||
| Welcome
to Tech Support Forum home to more then 136,000 problems solved. Issues
have included: Spyware, Malware, Virus Issues, Windows, Microsoft,
Linux, Networking, Security, Hardware, and Gaming Getting your
problem solved is as easy as: 1. Registering for a free account 2. Asking your question 3. Receiving an answer Registered members: * See fewer ads. * And much more..
|
| Want to know how to post a question? click here | Having problems with spyware and pop-ups? First Steps |
|
|||||||
| Microsoft Office support MS Office support forum |
![]() |
|
|
LinkBack | Thread Tools |
|
|
#1 (permalink) |
|
Registered User
Join Date: Oct 2008
Posts: 3
OS: XP
|
Need help with macros in Word 2003
Hi!
I've got some problems with the macro function in Word 2003. I'm swedish so if my spelling and grammar are'nt top notch thats the reason. Anyway. I've been assigned to a very repetative task at my workplace and i think macros could help me alot. I'm supposed to change company name in an allready existing document and then save the document with the company's name, and then repeat the whole thing like a million times with different company names. This is how I do it at the moment: Write the name of the company in the right place in the document > mark the name of the company > copy > save as > paste the company name > save. Is it possible to create a macro so that I only have to do the first steps like this: Write the name of the company > mark the name > the macro does the rest. Any help would be much appreciated! //Lucas, Sweden |
|
|
|
| Important Information |
|
Join the #1 Tech Support Forum Today - It's Totally Free!
TechSupportForum.com is a leading support website for your computer needs. We offer free, friendly and personalized computer support. Why pay to have your computer fixed when you can do it for free. Join TechSupportforum.com Today - Click Here |
|
|
#2 (permalink) |
|
Registered User
Join Date: May 2008
Location: Baltimore, Maryland
Posts: 160
OS: Windows XP SP3
|
Re: Need help with macros in Word 2003
The following example may be helpful.
Code:
Sub SaveUtility()
Dim fdir As String
Dim fname As String
Dim fspec As String
Dim response As Long
fdir = "C:\Documents and Settings\Default User\"
fname = Selection.Text
fspec = fdir & fname
If Dir(fspec, vbArchive Or vbDirectory Or vbHidden Or vbNormal Or vbReadOnly Or vbSystem) > "" Then
response = MsgBox(fspec & " exists. Overwrite?", vbYesNo + vbQuestion, "SaveUtility")
If response = vbNo Then
Exit Sub
End If
ElseIf Dir(fspec & ".doc", vbArchive Or vbDirectory Or vbHidden Or vbNormal Or vbReadOnly Or vbSystem) > "" Then
response = MsgBox(fspec & ".doc exists. Overwrite?", vbYesNo + vbQuestion, "SaveUtility")
If response = vbNo Then
Exit Sub
End If
End If
Selection.WholeStory
Selection.Copy
Documents.Add DocumentType:=wdNewBlankDocument
Selection.PasteAndFormat wdPasteDefault
ActiveDocument.SaveAs FileName:=fspec, FileFormat:=wdFormatDocument
End Sub
The new document will not contain the macro code. The new document's name will normally end with the .doc extension. In the code, you can modify the value of the variable fdir to specify the folder where the new document will be saved. |
|
|
|
|
|
#3 (permalink) |
|
Registered User
Join Date: Oct 2008
Posts: 3
OS: XP
|
Re: Need help with macros in Word 2003
Aaaaaaaaaah! Thanks alot! Works perfect and this will save me alot of time
![]() Just one more question: what if I don't want the new file to pop up as a new window? I just want to keep working in the same document but with the new file name, just like you do when you go the normal way with File > Save As No need to hurry, just wondering! Once again: Thank you! //Lucas |
|
|
|
|
|
#4 (permalink) |
|
Registered User
Join Date: May 2008
Location: Baltimore, Maryland
Posts: 160
OS: Windows XP SP3
|
Re: Need help with macros in Word 2003
If you don't want the new file to pop up as a new window, simply remove these lines from the code:
Code:
Selection.WholeStory
Selection.Copy
Documents.Add DocumentType:=wdNewBlankDocument
Selection.PasteAndFormat wdPasteDefault
|
|
|
|
|
|
#5 (permalink) |
|
Registered User
Join Date: Oct 2008
Posts: 3
OS: XP
|
Re: Need help with macros in Word 2003
Aha, that's what I thought but i wasn't sure enough to try it out.
I finished all the documents yesterday thanks to your code, it made my work alot easier. Now i just have to print every document, double check them and put them in envalopes. I suppose you don't have a macro for that to.. ![]() Anyway, thanks for the help, the code might come in handy in the future too. //Lucas |
|
|
|
![]() |
| Thread Tools | |
|
|