PDA

View Full Version : Help on looping macro code and not repeating myself



windowsxprel
05-22-2014, 06:32 PM
Hi. I have been going at this for a long time now, I am pretty sure it's been over a week, but can someone please help me out by looking at the following code and telling me if there's an easier way to write it instead of me repeating myself over and over. Your help would be really appreciated!!!!


' FILE NAME = LoQUo_01_01_d
ActiveDocument.SaveAs2 FileName:="LoQUo_01_01_d.iim", FileFormat:= _
wdFormatText, LockComments:=False, Password:="", AddToRecentFiles:=True, _
WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _
SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:= _
False, Encoding:=msoEncodingUTF8, InsertLineBreaks:=False, AllowSubstitutions:=False _
, LineEnding:=wdCRLF, CompatibilityMode:=0

' NEXT MACROS
ActiveDocument.MailMerge.DataSource.ActiveRecord = wdNextRecord

' FILE NAME = LoQUo_01_02_d
ActiveDocument.SaveAs2 FileName:="LoQUo_01_02_d.iim", FileFormat:= _
wdFormatText, LockComments:=False, Password:="", AddToRecentFiles:=True, _
WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _
SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:= _
False, Encoding:=msoEncodingUTF8, InsertLineBreaks:=False, AllowSubstitutions:=False _
, LineEnding:=wdCRLF, CompatibilityMode:=0

' NEXT MACROS
ActiveDocument.MailMerge.DataSource.ActiveRecord = wdNextRecord

' FILE NAME = LoQUo_02_01_d
ActiveDocument.SaveAs2 FileName:="LoQUo_02_01_d.iim", FileFormat:= _
wdFormatText, LockComments:=False, Password:="", AddToRecentFiles:=True, _
WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _
SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:= _
False, Encoding:=msoEncodingUTF8, InsertLineBreaks:=False, AllowSubstitutions:=False _
, LineEnding:=wdCRLF, CompatibilityMode:=0

' NEXT MACROS
ActiveDocument.MailMerge.DataSource.ActiveRecord = wdNextRecord

' FILE NAME = LoQUo_02_02_d
ActiveDocument.SaveAs2 FileName:="LoQUo_02_02_d.iim", FileFormat:= _
wdFormatText, LockComments:=False, Password:="", AddToRecentFiles:=True, _
WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _
SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:= _
False, Encoding:=msoEncodingUTF8, InsertLineBreaks:=False, AllowSubstitutions:=False _
, LineEnding:=wdCRLF, CompatibilityMode:=0

Tommy
07-31-2014, 12:16 PM
Having nothing to test with this is my first best guess. :)

Sub MailMerge()
Dim mFileTemp(3) As String, mI As Integer
For mI = 0 To UBound(mFileTemp, 1)
DoASaveAs mFileTemp(mI)
ActiveDocument.MailMerge.DataSource.ActiveRecord = wdNextRecord
Next
End Sub
Private Sub DoASaveAs(iFileName As String)
ActiveDocument.SaveAs2 Filename:=iFileName, FileFormat:= _
wdFormatText, LockComments:=False, Password:="", AddToRecentFiles:=True, _
WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _
SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:= _
False, Encoding:=msoEncodingUTF8, InsertLineBreaks:=False, AllowSubstitutions:=False _
, LineEnding:=wdCRLF, CompatibilityMode:=0
End Sub