Visual Basic Macro

R

rog982001

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
 
D

Doug Robbins - Word MVP

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.


--
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top