Consulting

Results 1 to 2 of 2

Thread: Help on looping macro code and not repeating myself

  1. #1

    Help on looping macro code and not repeating myself

    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

  2. #2
    Moderator VBAX Master Tommy's Avatar
    Joined
    May 2004
    Location
    Houston, TX
    Posts
    1,184
    Location
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •