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.
as always thanks in advance
Carl
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: