Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / March 2008

Tip: Looking for answers? Try searching our database.

Visual Basic Macro

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
rog982001 - 28 Mar 2008 21:09 GMT
I got MS Word to write a macro for me. It didn't work. The macro should
perform the following tasks on a merged document. The document is merged with
an Excel spreadsheet and an MS Word template. The fields on the Word document
are filled-in with the data from Excel. This part works just fine and creates
approximately 3,800 letters!



The MS Word macro must:



1. Save each letter in a separate file.

a. Pull the control number from each document.

b. Save each file as "CB xxx.doc" where xxx is the control number.

2. Advance to the next letter in the file.

3. Repeat steps (1) and (2).



This is the code that I have so far. If some one could expand on the hard
coded line:



RESEARCH_BEGINNING_DATE = "101"



The number 101 should be a variable not a constant.



Roger



Sub Macro2()
'
' Macro2 Macro
' Macro recorded 3/28/2008 by Customer Services
'
Set myRange = ActiveDocument.Range(Start:=0, End:=1)
   RESEARCH_BEGINNING_DATE = "101"
   FileName = "Charge Back" & RESEARCH_BEGINNING_DATE & ".doc"
   ActiveDocument.SaveAs FileName, FileFormat:= _
       wdFormatDocument, LockComments:=False, Password:="",
AddToRecentFiles:= _
       True, WritePassword:="", ReadOnlyRecommended:=False,
EmbedTrueTypeFonts:= _
       False, SaveNativePictureFormat:=False, SaveFormsData:=False, _
       SaveAsAOCELetter:=False
   Selection.MoveDown Unit:=wdScreen, Count:=4
   Selection.HomeKey Unit:=wdLine
End Sub

Signature

Roger

Doug Robbins - Word MVP - 29 Mar 2008 03:31 GMT
See the "Individual Merge Letters" item on fellow MVP Graham Mayor's website
at:

http://www.gmayor.com/individual_merge_letters.htm

If you are using Word XP or later, the "Add-in to Merge Letters to Separate
Files" that I have written and that can be downloaded from that site will
allow you to create each letter as a separate file with a filename taken
from a field in the data source with a minimum of fuss.

Signature

Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

>I got MS Word to write a macro for me. It didn't work. The macro should
> perform the following tasks on a merged document. The document is merged
[quoted text clipped - 44 lines]
>    Selection.HomeKey Unit:=wdLine
> End Sub
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.