PDA

View Full Version : [SOLVED] need help with VB script, error on cancel..



RompStar
06-01-2005, 02:03 PM
Here is a script that I found on the internet, I modified it very slightly....

The script works, but...

If I run the script the Input Box comes up..., if I continue on, it's all good, but if i change my mind and press cancel I get this error:, it bugs me that there is an error, would like to figure it out, but my knowhow is still limited, I am in the progress of learning...

The error is:

Run-time error '424'; Object required... :dunno


Sub rPrint()
' Works from the sheet module that it is to work from.
Dim myRange As Range
With ActiveSheet.PageSetup
.PrintTitleRows = "$9:$9" ' where my headers are at
.PrintTitleColumns = ""
End With
Worksheets("Master").Activate
Set myRange = Application.InputBox( _
Prompt:="Select a Range to print!" & Chr(13) & Chr(13) & "Use your mouse!" & Chr(13) _
& "For more than one Range add a ""comma"" between your selected Ranges!", Type:=8)
myRange.Select
MsgBox "Ready to print: " & Selection.Address
ActiveSheet.PageSetup.PrintArea = Selection.Address
ActiveSheet.PageSetup.FitToPagesWide = 1
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
Sheets("Master").Range("A1").Select
End Sub

Bob Phillips
06-01-2005, 03:26 PM
The error is:

Run-time error '424'; Object required...



Sub rPrint()
' Works from the sheet module that it is to work from.
Dim myRange As Range
With ActiveSheet.PageSetup
.PrintTitleRows = "$9:$9" ' where my headers are at
.PrintTitleColumns = ""
End With
Worksheets("Master").Activate
On Error Resume Next
Set myRange = Application.InputBox( _
Prompt:="Select a Range to print!" & Chr(13) & Chr(13) & "Use your mouse!" & Chr(13) _
& "For more than one Range add a ""comma"" between your selected Ranges!", Type:=8)
On Error GoTo 0
If Not myRange Is Nothing Then
myRange.Select
MsgBox "Ready to print: " & Selection.Address
ActiveSheet.PageSetup.PrintArea = Selection.Address
ActiveSheet.PageSetup.FitToPagesWide = 1
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
Sheets("Master").Range("A1").Select
End If
End Sub

RompStar
06-02-2005, 08:01 AM
I see I see :yes

thanks...

I like VBA, kinda fun to learn, thanks.