K
khalid
I am using a VB program to do Word mail merge. The program has been working fine with NT and Word 97. Now as we started to use Window 2000 and Word 2002 (XP) I started to get Section Break problem in the main merged document.
When the program cut and paste the new merged letter into the main document, sometime it insert a Section Break(Continuous) and other times it insert a Section Break(Next page) after the merged letter. I added an "InsertBreak" command to force the new letter on the next page, but on some PCs it insert an extra blank page.
I am not able to figure out why it is happening like this. I hope I have explained my problem.
I am using following VB code:
If Val(WrdApp.Version) >= 10 Then ' 'Word XP
WrdApp.ActiveDocument.MailMerge.OpenDataSource Name:="", Format:=wdOpenFormatAuto, _
ConfirmConversions:=False, ReadOnly:=False, LinkToSource:=False, AddToRecentFiles:=False, _
PasswordDocument:="", PasswordTemplate:="", WritePasswordDocument:="", _
WritePasswordTemplate:="", Revert:=False, _
Connection:= _
"dsn=" & DSN & ";UID=" & UserId & ";PWD=" & Password & ";" _
, SQLStatement:=mSelection1 _
, SQLStatement1:=mSelection2, SubType:=wdMergeSubTypeWord2000
Else
WrdApp.ActiveDocument.MailMerge.OpenDataSource Name:="", Format:=wdOpenFormatAuto, _
ConfirmConversions:=False, ReadOnly:=False, LinkToSource:=False, AddToRecentFiles:=False, _
PasswordDocument:="", PasswordTemplate:="", WritePasswordDocument:="", _
WritePasswordTemplate:="", Revert:=False, _
Connection:= _
"dsn=" & DSN & ";UID=" & UserId & ";PWD=" & Password & ";" _
, SQLStatement:=mSelection1 _
, SQLStatement1:=mSelection2
End If
With WrdApp.ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.MailAsAttachment = False
.MailAddressFieldName = ""
.MailSubject = ""
.SuppressBlankLines = True
.Execute
End With
'Select all letters for current template in new file
WrdApp.ActiveDocument.Select
'put selection into clipboard
WrdApp.Selection.Copy
'close letter file in Word without changes
WrdApp.ActiveDocument.Close wdDoNotSaveChanges
'close template file in Word without changes
WrdApp.ActiveDocument.Close wdDoNotSaveChanges
'paste all letters merged from current template into new file
WrdApp.Selection.Paste
If Val(WrdApp.Version) >= 10 Then ' 'Word XP
WrdApp.Selection.InsertBreak ' 'Type:=wdPageBreak
End If
Thanks
Khalid
When the program cut and paste the new merged letter into the main document, sometime it insert a Section Break(Continuous) and other times it insert a Section Break(Next page) after the merged letter. I added an "InsertBreak" command to force the new letter on the next page, but on some PCs it insert an extra blank page.
I am not able to figure out why it is happening like this. I hope I have explained my problem.
I am using following VB code:
If Val(WrdApp.Version) >= 10 Then ' 'Word XP
WrdApp.ActiveDocument.MailMerge.OpenDataSource Name:="", Format:=wdOpenFormatAuto, _
ConfirmConversions:=False, ReadOnly:=False, LinkToSource:=False, AddToRecentFiles:=False, _
PasswordDocument:="", PasswordTemplate:="", WritePasswordDocument:="", _
WritePasswordTemplate:="", Revert:=False, _
Connection:= _
"dsn=" & DSN & ";UID=" & UserId & ";PWD=" & Password & ";" _
, SQLStatement:=mSelection1 _
, SQLStatement1:=mSelection2, SubType:=wdMergeSubTypeWord2000
Else
WrdApp.ActiveDocument.MailMerge.OpenDataSource Name:="", Format:=wdOpenFormatAuto, _
ConfirmConversions:=False, ReadOnly:=False, LinkToSource:=False, AddToRecentFiles:=False, _
PasswordDocument:="", PasswordTemplate:="", WritePasswordDocument:="", _
WritePasswordTemplate:="", Revert:=False, _
Connection:= _
"dsn=" & DSN & ";UID=" & UserId & ";PWD=" & Password & ";" _
, SQLStatement:=mSelection1 _
, SQLStatement1:=mSelection2
End If
With WrdApp.ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.MailAsAttachment = False
.MailAddressFieldName = ""
.MailSubject = ""
.SuppressBlankLines = True
.Execute
End With
'Select all letters for current template in new file
WrdApp.ActiveDocument.Select
'put selection into clipboard
WrdApp.Selection.Copy
'close letter file in Word without changes
WrdApp.ActiveDocument.Close wdDoNotSaveChanges
'close template file in Word without changes
WrdApp.ActiveDocument.Close wdDoNotSaveChanges
'paste all letters merged from current template into new file
WrdApp.Selection.Paste
If Val(WrdApp.Version) >= 10 Then ' 'Word XP
WrdApp.Selection.InsertBreak ' 'Type:=wdPageBreak
End If
Thanks
Khalid