View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
SJW_OST[_2_] SJW_OST[_2_] is offline
external usenet poster
 
Posts: 39
Default Assigned macro in Dialog giving error

I used the code you gave but still got the Error

PrintOut method of Worksheet class failed

I've noticed that when I "F8" thru my code, starting with

Sub Dialog()
'
DialogSheets("Dialog1").Show
End Sub

The above code does not end until the Dialog box closes. Could this be a
part of what is causeing the problem? The PRNT code you gave works if I use
it by itself but when assigned to the PRINT Button on the Dialog and
activated by clicking he Button is when the error occurs.

"JLGWhiz" wrote:

Try this:

Sub PRNT()
With Sheets("Sheet2")
For Each c In .Range("A1:A3")
If c.Address = "$A$1" And c = True Then
Sheets("Sjeet1").PrintOut
ElseIf c.Address = "$A$2" And c = True Then
Sheets("Sheet2").PrintOut
ElseIf c.Address = "$A$3" And c = True Then
Sheets("Sheet3").Printout
End If
Next
End With
MsgBox "Sheets for all checked boxes have printed"
End Sub



"SJW_OST" wrote:

Hello,
I have a Dialog box which contains 3 Check Boxes & 2 Buttons. I am using
this code to bring up the Dialog.

Sub Dialog()
'
DialogSheets("Dialog1").Show
End Sub

The 3 Check Boxes place a TRUE or FALSE in specific cells depending on if
the box is checked and the 2 Buttons are PRINT & Cancel. I have assigned this
code to the PRINT button.

Sub PRNT()
'
Sheets("Sheet2").Select
If Range("A1") = True Then
MyString = Sheets("Sheet1").Select
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
Else: Sheets("Sheet2").Select
Range("A1").Select
End If
If Range("A2") = True Then
MyString = Sheets("Sheet2").Select
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
Else: Sheets("Sheet2").Select
Range("A1").Select
End If
If Range("A3") = True Then
MyString = Sheets("Sheet3").Select
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
Else: Sheets("Sheet2").Select
Range("A1").Select
End If
MsgBox "All checked boxes have been printed."
End Sub

The problem comes when any of the Check Boxes is checked and the above macro
is activated by clicking PRINT in the Dialog. I get;

Method 'PrintOut' of object 'Sheets' failed

I've looked at all of the attributes I know of, which is admittedly few, and
tried finding a solution via MS Help to no avail. Can some one help me with
this? I want to be able to print only the selected sheets based on which
Check Box has a check in it by clicking my PRINT Button in my Dialog.
Thank you for your help.