• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Print the Active Sheets

sgmpatnaik

Active Member
Hell Sir,


Kindly help me about this mistake, i can't understand where is my mistake


Private Sub CommandButton1_Click()

Dim sh As Worksheet

Set sh = ActiveSheet

Worksheets(Array("Sheet1")).PrintPreview

sh.Select

ActiveSheet = MsgBox("Do you want print" & ActiveSheet.Item, vbOKCancel,"PrintPreview")

Worksheet.Item.PrintPreview True


End Sub


With Regards


Patnaik
 
The output of the MsgBox is going to be vbOk or vbCancel, thus you can't set the ActiveSheet equal to it. Usually you want have a variable take the output of the MsgBox and then test the variable to see what the response was.


Also, not sure what "ActiveSheet.Item" is supposed to be referring to. This is also causing errors for me.
 
Thank Q Luke M Sir,


if you don't mind please help me with the perfect VB Code


i am success up to 80 % but the rest 20 % is mistake against the below code


Private Sub CommandButton1_Click()

Dim sh As Worksheet

Set sh = ActiveSheet

Worksheets(Array("Sheet1")).PrintPreview

sh.Select

ActiveSheet = MsgBox("Do you want print " & ActiveSheet.Name, vbOKCancel, "PrintPreview")

If sh = 1 Then

Set sh = ActiveSheet.Name.PrintPreview


ActiveSheet.Name.PrintPreview True


End If


End Sub


hence i oblige


Thanking you


With regards


Patnaik
 
Still not 100% sure what your intent was, but this code doesn't generate any errors at least.

[pre]
Code:
Private Sub CommandButton1_Click()
Dim sh As Worksheet
Dim xChoice As Variant

Set sh = ActiveSheet
'Now that we've defined sh, don't refer to Activesheet again

sh.PrintPreview
sh.Select
xChoice = MsgBox("Do you want print " & sh.Name, vbOKCancel, "PrintPreview")
If xChoice = vbOK Then
'Is this really want you want, to back to print preview?
sh.PrintPreview True

'Or did you really want to print using this line:
'sh.PrintOut
End If

End Sub
[/pre]
 
Back
Top