G
G-Oker
Hello,
I've been writing a word macro that takes 2 excel files and merges
them into 2 different documents.
What I am trying to do is to count the Records being merged and
display them in a message box.
However, where ever I put MsgBox .RecordCount, I get a message box
saying -1.
The code I am currently using is :-
Sub MergeStickers()
'
' MergeStickersMacro
' Macro recorded 3/19/2007 by GOakham
'
strFileZ = Format$(Date, "yy-mm ")
Const sFILE As String = "Fulfillment"
Const sPATH As String = "\\Server\Dir\Dir2\Dir3\"
Const sVAR As String = ""
Const sVAR2 As String = " UK"
ChangeFileOpenDirectory "\\Server\Dir\Dir2\Dir3\"
Documents.Open FileName:="New Merge Settings2.doc",
ConfirmConversions:=False, ReadOnly:=False, AddToRecentFiles:=False,
PasswordDocument:="", _
PasswordTemplate:="", Revert:=False,
WritePasswordDocument:="", _
WritePasswordTemplate:="", Format:=wdOpenFormatAuto
ActiveDocument.MailMerge.MainDocumentType = wdFormLetters
ActiveDocument.MailMerge.OpenDataSource Name:=sPATH & sVAR & _
Format(Now - 1, "dd-mm-yy ") & sFILE & ".csv" _
, ConfirmConversions:=False, ReadOnly:=False,
LinkToSource:=True, _
AddToRecentFiles:=False, PasswordDocument:="",
PasswordTemplate:="", _
WritePasswordDocument:="", WritePasswordTemplate:="",
Revert:=False, _
Format:=wdOpenFormatAuto, Connection:="", SQLStatement:="",
SQLStatement1 _
:="", SubType:=wdMergeSubTypeOther
With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
LNewDOC = ActiveDocument.Name
End With
.Execute Pause:=False
End With
' Windows("New Merge Settings 2.doc").Activate
' ActiveWindow.ActivePane.VerticalPercentScrolled = 0
' Windows(1).Activate
'MsgBox ActiveDocument.Sections.Count & " Pages."
'MsgBox ActiveDocument.MailMerge.DataSource.RecordCount
''
ChangeFileOpenDirectory "\\Server\Dir\Dir2\Dir3\"
Documents.Open FileName:="New Merge Settings2.doc",
ConfirmConversions:=False, ReadOnly:=False, AddToRecentFiles:=False,
PasswordDocument:="", _
PasswordTemplate:="", Revert:=False,
WritePasswordDocument:="", _
WritePasswordTemplate:="", Format:=wdOpenFormatAuto
ActiveDocument.MailMerge.MainDocumentType = wdFormLetters
ActiveDocument.MailMerge.OpenDataSource Name:=sPATH & sVAR & _
Format(Now - 1, "dd-mm-yy ") & sFILE & sVAR2 & ".csv" _
, ConfirmConversions:=False, ReadOnly:=False,
LinkToSource:=True, _
AddToRecentFiles:=False, PasswordDocument:="",
PasswordTemplate:="", _
WritePasswordDocument:="", WritePasswordTemplate:="",
Revert:=False, _
Format:=wdOpenFormatAuto, Connection:="", SQLStatement:="",
SQLStatement1 _
:="", SubType:=wdMergeSubTypeOther
With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute Pause:=False
End With
MsgBox "Auto Merge complete.Now put the stickers in the Printer,and
press the OK Button", vbInformation, "Phew...Finished"
End Sub
Any help would be great
I've been writing a word macro that takes 2 excel files and merges
them into 2 different documents.
What I am trying to do is to count the Records being merged and
display them in a message box.
However, where ever I put MsgBox .RecordCount, I get a message box
saying -1.
The code I am currently using is :-
Sub MergeStickers()
'
' MergeStickersMacro
' Macro recorded 3/19/2007 by GOakham
'
strFileZ = Format$(Date, "yy-mm ")
Const sFILE As String = "Fulfillment"
Const sPATH As String = "\\Server\Dir\Dir2\Dir3\"
Const sVAR As String = ""
Const sVAR2 As String = " UK"
ChangeFileOpenDirectory "\\Server\Dir\Dir2\Dir3\"
Documents.Open FileName:="New Merge Settings2.doc",
ConfirmConversions:=False, ReadOnly:=False, AddToRecentFiles:=False,
PasswordDocument:="", _
PasswordTemplate:="", Revert:=False,
WritePasswordDocument:="", _
WritePasswordTemplate:="", Format:=wdOpenFormatAuto
ActiveDocument.MailMerge.MainDocumentType = wdFormLetters
ActiveDocument.MailMerge.OpenDataSource Name:=sPATH & sVAR & _
Format(Now - 1, "dd-mm-yy ") & sFILE & ".csv" _
, ConfirmConversions:=False, ReadOnly:=False,
LinkToSource:=True, _
AddToRecentFiles:=False, PasswordDocument:="",
PasswordTemplate:="", _
WritePasswordDocument:="", WritePasswordTemplate:="",
Revert:=False, _
Format:=wdOpenFormatAuto, Connection:="", SQLStatement:="",
SQLStatement1 _
:="", SubType:=wdMergeSubTypeOther
With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
LNewDOC = ActiveDocument.Name
End With
.Execute Pause:=False
End With
' Windows("New Merge Settings 2.doc").Activate
' ActiveWindow.ActivePane.VerticalPercentScrolled = 0
' Windows(1).Activate
'MsgBox ActiveDocument.Sections.Count & " Pages."
'MsgBox ActiveDocument.MailMerge.DataSource.RecordCount
''
ChangeFileOpenDirectory "\\Server\Dir\Dir2\Dir3\"
Documents.Open FileName:="New Merge Settings2.doc",
ConfirmConversions:=False, ReadOnly:=False, AddToRecentFiles:=False,
PasswordDocument:="", _
PasswordTemplate:="", Revert:=False,
WritePasswordDocument:="", _
WritePasswordTemplate:="", Format:=wdOpenFormatAuto
ActiveDocument.MailMerge.MainDocumentType = wdFormLetters
ActiveDocument.MailMerge.OpenDataSource Name:=sPATH & sVAR & _
Format(Now - 1, "dd-mm-yy ") & sFILE & sVAR2 & ".csv" _
, ConfirmConversions:=False, ReadOnly:=False,
LinkToSource:=True, _
AddToRecentFiles:=False, PasswordDocument:="",
PasswordTemplate:="", _
WritePasswordDocument:="", WritePasswordTemplate:="",
Revert:=False, _
Format:=wdOpenFormatAuto, Connection:="", SQLStatement:="",
SQLStatement1 _
:="", SubType:=wdMergeSubTypeOther
With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute Pause:=False
End With
MsgBox "Auto Merge complete.Now put the stickers in the Printer,and
press the OK Button", vbInformation, "Phew...Finished"
End Sub
Any help would be great