Create Print button that print another sheet

Unexpc

Active Member
Joined
Nov 12, 2020
Messages
496
Office Version
  1. 2019
Platform
  1. Windows
Hi guys
how to create a vba button for print preview or quick print from another sheet?
 
If your Print Button In Page work Correctly, You can its macro to Quick access toolbar.
Select down arrow at the end of quick access toolbar. Then Select More Command.
Change Popular commands to Macro and then Select your Macro name for Print.
 
Upvote 0

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
If your Print Button In Page work Correctly, You can its macro to Quick access toolbar.
Select down arrow at the end of quick access toolbar. Then Select More Command.
Change Popular commands to Macro and then Select your Macro name for Print.
i see, you are right, but onething, this is specific for one sheet...
for example i use one macro for printout sheet2 in sheet 1 and like this, sheet3 in sheet4 and... there is same formula but different target range, how can i set button different for each sheet not main worksheet?
 
Upvote 0
Upload your print button code here to see. I forgot it.
 
Upvote 0
Upload your print button code here to see. I forgot it.
This is
VBA Code:
Sub PageTestForPrint()
Dim MyRange As Range
Dim ws As Worksheet
Dim Lastrow As Long
Dim i As Long
Dim n As Long
Dim PrintArea As String
Application.ScreenUpdating = False
Set ws = ActiveSheet
Sheets("Sheet2").Visible = True
Sheets("Sheet2").Select
For i = 1 To 30840
If Cells(34 * i + 8, 1).Value <> "" Then
n = i + 1
Else
GoTo Printing
End If
Next i
Printing:
Debug.Print n
Sheets("sheet2").PrintOut
Sheets("Sheet2").Visible = False
Sheets("Sheet1").Select
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Are your code for sheet3 & sheet4 different than this?
 
Upvote 0
Change all of
Sheets("Sheet2")
to
ws

this print activesheet I think
 
Upvote 0
Are your code for sheet3 & sheet4 different than this?
Sheet1->Sheet3
Sheet2->Sheet4
And other sheets like this
I mean when i select quick print button in Sheet1, that quick print from Sheet2 and when use quick print button in Sheet3, print Sheet4 and... this is difference
 
Upvote 0
Test this. Print One sheet after Activesheet Always.
VBA Code:
Sub PageTestForPrint()
Dim MyRange As Range
Dim ws As Worksheet
Dim Lastrow As Long
Dim i As Long
Dim n As Long
Dim j As Long
Dim PrintArea As String
Application.ScreenUpdating = False
Set ws = ActiveSheet
j = ActiveSheet.Index
Debug.Print j
Sheets(j + 1).Visible = True
Sheets(j + 1).Select
For i = 1 To 30840
If Cells(34 * i + 8, 1).Value <> "" Then
n = i + 1
Else
GoTo Printing
End If
Next i
Printing:
Debug.Print n
Sheets(j + 1).PrintOut
Sheets(j + 1).Visible = False
Sheets(j).Select
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Test this. Print One sheet after Activesheet Always.
VBA Code:
Sub PageTestForPrint()
Dim MyRange As Range
Dim ws As Worksheet
Dim Lastrow As Long
Dim i As Long
Dim n As Long
Dim j As Long
Dim PrintArea As String
Application.ScreenUpdating = False
Set ws = ActiveSheet
j = ActiveSheet.Index
Debug.Print j
Sheets(j + 1).Visible = True
Sheets(j + 1).Select
For i = 1 To 30840
If Cells(34 * i + 8, 1).Value <> "" Then
n = i + 1
Else
GoTo Printing
End If
Next i
Printing:
Debug.Print n
Sheets(j + 1).PrintOut
Sheets(j + 1).Visible = False
Sheets(j).Select
Application.ScreenUpdating = True
End Sub
Very Smart?, can give a name for sheet that print from? For example Sheet2 is printsheet Sheet1 named Print1 and Sheet 4 printsheet Sheet3 named Print2 that i can named sheets order, Sheet1,2,3... main sheet and Print1,2,3... printsheet from Sheet number order
 
Upvote 0
VBA Code:
Sub PageTestForPrint()
Dim MyRange As Range
Dim ws As Worksheet
Dim Lastrow As Long
Dim i As Long
Dim n As Long
Dim j As Long
Dim PrintArea As String
Application.ScreenUpdating = False
Set ws = ActiveSheet
j = ActiveSheet.Index
Sheets(j + 1).Visible = True
Sheets(j + 1).Select
Debug.Print ws.Range("A1").Value
For i = 1 To 30840
If Cells(34 * i + 8, 1).Value <> "" Then
n = i + 1
Else
GoTo Printing
End If
Next i

Printing:
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:="Print" & (j + 1) / 2 _
    , Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
    :=False, OpenAfterPublish:=True

Sheets(j + 1).Visible = False
Sheets(j).Select
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,224,827
Messages
6,181,197
Members
453,021
Latest member
pingpong7117

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top