print a sheet from another sheet

dappy

Board Regular
Joined
Apr 23, 2018
Messages
124
Office Version
  1. 2013
Platform
  1. Windows
hi (again) folks.

I have a work book with several sheets that need printing. at the moment the print code only works with the active sheet and i cant figure out how to put a print button on a different sheet to print.

currently my code (stolen from somewhere :( ) its opens the txt file and copies the active sheet ok but if i copy the button to another sheet it prints that sheet out instead of the one intende.



VBA Code:
Dim iLastRow As Long
Dim iLastCol As Long


iLastRow = Range("A" & Rows.Count).End(xlUp).Row
iLastCol = Cells(1, Columns.Count).End(xlToLeft).Column
    Open "C:\temp\hopping.txt" For Output As [URL='https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=1']#1[/URL]
        For i = 1 To iLastRow
            For j = 1 To iLastCol
                If j <> iLastCol Then 'keep writing to same line
                    Print [URL='https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=1']#1[/URL] , Cells(i, j),
                Else 'end the line
                    Print [URL='https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=1']#1[/URL] , Cells(i, j)
                End If
            Next j
        Next i
        'MsgBox "Failed to transfer " & iFail & " file(s).", iFail & " Transfer(s) Failed"
    Close [URL='https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=1']#1[/URL]
    'comment the shell command out if you don't want to open the file when the macro ends
    Shell "notepad.exe ""C:\temp\hopping.txt", vbNormalFocus


Close #1

as always thanks in advance
Carl
 
Last edited by a moderator:

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
that should be that i have a button already but if i copy the button/code to another sheet it prints that sheet and not the one intended.
 
Upvote 0

Forum statistics

Threads
1,215,886
Messages
6,127,586
Members
449,386
Latest member
owais87

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