0

I have macro button in excel which has the following code and printing accordingly

Private Sub CommandButton10_Click()

MsgBox "SET YOUR PRINTER &  CLICK OK"
    Range("B18:B58").Select
    Selection.Copy
    ActiveWindow.SmallScroll Down:=-33
    Range("bf18").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Application.CutCopyMode = False
    Range("A1").Select
    ActiveSheet.PageSetup.PrintArea = "$L$775:$AN$818"
    'ActiveWindow.SelectedSheets.printout Copies:=1, Collate:=True
    'ActiveSheet.PageSetup.PrintArea = "$ay$520:$be$523"
    'Range("A1").Select
'ActiveWindow.SelectedSheets.printout Copies:=1, Collate:=True

ActiveWindow.SelectedSheets.PrintPreview
End Sub

. if the button clicks this will print to the default printer directly,but i want to make an option to cancel the printer as if someone clicks the button can go back also ..how to do it with the above code

thnk u

1 Answer 1

1

MsgBox can return what was pressed, so you can use it in an if statement.

So;

Private Sub CommandButton10_Click() 'Give this a name!
    If MsgBox("SET YOUR PRINTER & CLICK OK", vbOKCancel) = vbOK Then
        Range("B18:B58").Select
        Selection.Copy
        ActiveWindow.SmallScroll Down:=-33
        Range("bf18").Select
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
        Application.CutCopyMode = False
        Range("A1").Select
        ActiveSheet.PageSetup.PrintArea = "$L$775:$AN$818"
        'ActiveWindow.SelectedSheets.printout Copies:=1, Collate:=True
        'ActiveSheet.PageSetup.PrintArea = "$ay$520:$be$523"
        'Range("A1").Select
        'ActiveWindow.SelectedSheets.printout Copies:=1, Collate:=True

        ActiveWindow.SelectedSheets.PrintPreview
    End If
End Sub
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.