P
Peter L Kessler
Hello
I've been maintaining a set of Word VBA macros for a few years at the
office, and have a routine which prints the current document to a pre-set
printer and tray(s). The pre-sets have been saved in the Registry, so the
routine pulls these out and uses them to reset the ActivePrinter, print the
document and then reset the ActivePrinter from saved data.
This works fine for Word 97 (on Win 98 & 2000) and Word 2000 (Win2000 & XP).
Word 2002 (Win XP) crashes completely (not just a VBA error, but Word
itself) when it reaches the line which alters the DefaultTray to the saved
setting. I have pasted the essential elements of the routine below. I'm
hoping someone will be able to tell me why this is happening with the "new
and improved" Word, when the old versions work quite happily with it. Any
help is greatly appreciated.
Best wishes
Peter Kessler
Kessler Associates
E: (e-mail address removed)
W: http://www.digital.kessler-web.co.uk
Public PrintDocument()
Dim SelectedComboBox As String
'Get the saved printer and tray settings from the Registry
cboCInvPrint1 = System.PrivateProfileString("", lsection,
"CInvPrint1")
cboCInvPrint2 = System.PrivateProfileString("", lsection,
"CInvPrint2")
cboCInvTray1 = System.PrivateProfileString("", lsection,
"CInvTray1")
cboCInvTray2 = System.PrivateProfileString("", lsection,
"CInvTray2")
SelectedComboBox = cboInvPrint1
ComboBoxChange
' Set Tray 1 for Page 1
If cboInvTray1 <> "" Then
With Options
.DefaultTray = cboInvTray1 '******************** Word
crashes here
End With
'Routine then prints page 1...
End Sub
Public ComboBoxChange()
With Dialogs(wdDialogFilePrintSetup)
.Printer = SelectedComboBox
.DoNotSetAsSysDefault = True
.Execute
End With
End Sub
I've been maintaining a set of Word VBA macros for a few years at the
office, and have a routine which prints the current document to a pre-set
printer and tray(s). The pre-sets have been saved in the Registry, so the
routine pulls these out and uses them to reset the ActivePrinter, print the
document and then reset the ActivePrinter from saved data.
This works fine for Word 97 (on Win 98 & 2000) and Word 2000 (Win2000 & XP).
Word 2002 (Win XP) crashes completely (not just a VBA error, but Word
itself) when it reaches the line which alters the DefaultTray to the saved
setting. I have pasted the essential elements of the routine below. I'm
hoping someone will be able to tell me why this is happening with the "new
and improved" Word, when the old versions work quite happily with it. Any
help is greatly appreciated.
Best wishes
Peter Kessler
Kessler Associates
E: (e-mail address removed)
W: http://www.digital.kessler-web.co.uk
Public PrintDocument()
Dim SelectedComboBox As String
'Get the saved printer and tray settings from the Registry
cboCInvPrint1 = System.PrivateProfileString("", lsection,
"CInvPrint1")
cboCInvPrint2 = System.PrivateProfileString("", lsection,
"CInvPrint2")
cboCInvTray1 = System.PrivateProfileString("", lsection,
"CInvTray1")
cboCInvTray2 = System.PrivateProfileString("", lsection,
"CInvTray2")
SelectedComboBox = cboInvPrint1
ComboBoxChange
' Set Tray 1 for Page 1
If cboInvTray1 <> "" Then
With Options
.DefaultTray = cboInvTray1 '******************** Word
crashes here
End With
'Routine then prints page 1...
End Sub
Public ComboBoxChange()
With Dialogs(wdDialogFilePrintSetup)
.Printer = SelectedComboBox
.DoNotSetAsSysDefault = True
.Execute
End With
End Sub