M
Marrow
I have a mailmerge document that is linked to a template with some vba
in it as below.
The data is held in a spreadsheet in four differenet ranges and only
one is used for the mailmerge at any one time.
This was written in Office 95 and has worked fine until our company
decided to upgrade to Office 2003.
Now I get a Select Table dialog when the code runs and the user has to
select the range for the mailmerge. Before the change this was dealt
with in the code.
Can anybody suggest how to stop this dialog box appearing
Public Sub MAIN()
On Error GoTo -1: On Error GoTo ErrorHandler
Dim Filname$
Dim pathname$
ReDim DocList__$(6)
Dim quit
Dim Bookname$
Dim x
Dim rangename$
Application.ScreenUpdating = False
pathname$ = "H:\My Documents\Work\Retcalc\"
DocList__$(0) = "TV Letter"
DocList__$(1) = "TV Pack"
DocList__$(2) = "PUP Letter"
DocList__$(3) = "PUP Pack"
DocList__$(4) = "RET Letter"
DocList__$(5) = "RET Pack"
DocList__$(6) = "REF Letter"
WordBasic.BeginDialog 320, 118, "Select type of output required"
WordBasic.Text 27, 8, 129, 13, ""
WordBasic.ListBox 29, 25, 160, 84, DocList__$(), "MyList"
WordBasic.OKButton 226, 5, 88, 21
WordBasic.CancelButton 226, 29, 88, 21
WordBasic.EndDialog
Dim dlg As Object: Set dlg = WordBasic.CurValues.UserDialog
WordBasic.CurValues.UserDialog dlg
x = WordBasic.Dialog.UserDialog(dlg)
If x = -1 Then
Select Case dlg.mylist
Case 0
Filname$ = "TVletter.doc"
rangename$ = "TV_output_range"
Case 1
Filname$ = "TVpack.doc"
rangename$ = "TV_output_range"
Case 2
Filname$ = "PUPletter.doc"
rangename$ = "PUP_output_range"
Case 3
Filname$ = "PUPpack.doc"
rangename$ = "PUP_output_range"
Case 4
Filname$ = "RETletter.doc"
rangename$ = "RET_output_range"
Case 5
Filname$ = "RETpack.doc"
rangename$ = "RET_output_range"
Case 6
Filname$ = "REFUNDletter.doc"
rangename$ = "REF_output_range"
Case Else
WordBasic.MsgBox "Not available."
quit = 1
End Select
If quit <> 1 Then
Open "H:\Bookname.txt" For Input As 1
Input #1, Bookname$
Close 1
WordBasic.FileOpen Name:=pathname$ + Filname$, ConfirmConversions:=0,
ReadOnly:=1, AddToMru:=0, PasswordDoc:="", PasswordDot:="", Revert:=0,
WritePasswordDoc:="", WritePasswordDot:=""
WordBasic.MailMergeMainDocumentType 0
frmMessage.Show vbmodless
frmMessage.Repaint
WordBasic.MailMergeOpenDataSource Name:=Bookname$,
ConfirmConversions:=0, ReadOnly:=1, LinkToSource:=1, AddToMru:=0,
PasswordDoc:="", PasswordDot:="", Revert:=0, WritePasswordDoc:="",
WritePasswordDot:="", Connection:=rangename$, SQLStatement:="",
SQLStatement1:=""
WordBasic.MailMergeViewData 1
Unload frmMessage
End If
End If
GoTo CodeEnd
ErrorHandler:
Select Case Err.Number
Case 53: WordBasic.MsgBox "The file does not exist."
Case 64: WordBasic.MsgBox "The specified drive is not available."
Case 76: WordBasic.MsgBox "The specified folder does not exist."
Case 102: WordBasic.MsgBox "Mailmerge cancelled."
Case 1544: WordBasic.MsgBox "Please close the source spreadsheet
and then try again"
Case Else: WordBasic.MsgBox "Error" + Str(Err.Number) + "
occurred."
End Select
Err.Number = 0
CodeEnd:
Unload frmMessage
Application.ScreenUpdating = True
End Sub
in it as below.
The data is held in a spreadsheet in four differenet ranges and only
one is used for the mailmerge at any one time.
This was written in Office 95 and has worked fine until our company
decided to upgrade to Office 2003.
Now I get a Select Table dialog when the code runs and the user has to
select the range for the mailmerge. Before the change this was dealt
with in the code.
Can anybody suggest how to stop this dialog box appearing
Public Sub MAIN()
On Error GoTo -1: On Error GoTo ErrorHandler
Dim Filname$
Dim pathname$
ReDim DocList__$(6)
Dim quit
Dim Bookname$
Dim x
Dim rangename$
Application.ScreenUpdating = False
pathname$ = "H:\My Documents\Work\Retcalc\"
DocList__$(0) = "TV Letter"
DocList__$(1) = "TV Pack"
DocList__$(2) = "PUP Letter"
DocList__$(3) = "PUP Pack"
DocList__$(4) = "RET Letter"
DocList__$(5) = "RET Pack"
DocList__$(6) = "REF Letter"
WordBasic.BeginDialog 320, 118, "Select type of output required"
WordBasic.Text 27, 8, 129, 13, ""
WordBasic.ListBox 29, 25, 160, 84, DocList__$(), "MyList"
WordBasic.OKButton 226, 5, 88, 21
WordBasic.CancelButton 226, 29, 88, 21
WordBasic.EndDialog
Dim dlg As Object: Set dlg = WordBasic.CurValues.UserDialog
WordBasic.CurValues.UserDialog dlg
x = WordBasic.Dialog.UserDialog(dlg)
If x = -1 Then
Select Case dlg.mylist
Case 0
Filname$ = "TVletter.doc"
rangename$ = "TV_output_range"
Case 1
Filname$ = "TVpack.doc"
rangename$ = "TV_output_range"
Case 2
Filname$ = "PUPletter.doc"
rangename$ = "PUP_output_range"
Case 3
Filname$ = "PUPpack.doc"
rangename$ = "PUP_output_range"
Case 4
Filname$ = "RETletter.doc"
rangename$ = "RET_output_range"
Case 5
Filname$ = "RETpack.doc"
rangename$ = "RET_output_range"
Case 6
Filname$ = "REFUNDletter.doc"
rangename$ = "REF_output_range"
Case Else
WordBasic.MsgBox "Not available."
quit = 1
End Select
If quit <> 1 Then
Open "H:\Bookname.txt" For Input As 1
Input #1, Bookname$
Close 1
WordBasic.FileOpen Name:=pathname$ + Filname$, ConfirmConversions:=0,
ReadOnly:=1, AddToMru:=0, PasswordDoc:="", PasswordDot:="", Revert:=0,
WritePasswordDoc:="", WritePasswordDot:=""
WordBasic.MailMergeMainDocumentType 0
frmMessage.Show vbmodless
frmMessage.Repaint
WordBasic.MailMergeOpenDataSource Name:=Bookname$,
ConfirmConversions:=0, ReadOnly:=1, LinkToSource:=1, AddToMru:=0,
PasswordDoc:="", PasswordDot:="", Revert:=0, WritePasswordDoc:="",
WritePasswordDot:="", Connection:=rangename$, SQLStatement:="",
SQLStatement1:=""
WordBasic.MailMergeViewData 1
Unload frmMessage
End If
End If
GoTo CodeEnd
ErrorHandler:
Select Case Err.Number
Case 53: WordBasic.MsgBox "The file does not exist."
Case 64: WordBasic.MsgBox "The specified drive is not available."
Case 76: WordBasic.MsgBox "The specified folder does not exist."
Case 102: WordBasic.MsgBox "Mailmerge cancelled."
Case 1544: WordBasic.MsgBox "Please close the source spreadsheet
and then try again"
Case Else: WordBasic.MsgBox "Error" + Str(Err.Number) + "
occurred."
End Select
Err.Number = 0
CodeEnd:
Unload frmMessage
Application.ScreenUpdating = True
End Sub