open spreadsheet in print view when clicked on command button

ManvinderKaur

Board Regular
Joined
Jun 16, 2010
Messages
149
Hi, I have 28 excel sheets in a workbook. There is one main form in workbook. When i click on one button 3 spreedsheets become visible.I need a button on each sheet, so that I can print out other sheets. How come I do that.
 

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092
Maybe try:

Code:
Sub Test()
    Dim ws As Worksheet
    For Each ws in Worksheets
        If ws.Visible Then ws.PrintOut
    Next ws
End Sub
 

ManvinderKaur

Board Regular
Joined
Jun 16, 2010
Messages
149
Thanks Andrew ..
But I want to modify my question ..
I want a button on one spreadsheet...when any one click on that button-they will get print out of another hidden sheet
Thanks
Manvinder
 

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092
To print a hidden sheet you need to unhide it first. Like this:

Code:
Sub Test()
    With Worksheets("Sheet1")
        .Visible = True
        .PrintOut
        .Visible = False
    End With
End Sub
 

ManvinderKaur

Board Regular
Joined
Jun 16, 2010
Messages
149
Thanks a lot
I have used the following code......It will show print preview of page..because this sheet is for different people in Australia...So I could not use .printout...because they have to select there own printer..so I showed only print preview....Any more suggestions????....



Private Sub cmdPrintSiteSurveyEnergy_Click()

Dim SiteSurveyEnegy As Integer
' message box to prompt print out
SiteSurveyEnegy = MsgBox("Do you want to take print out of Site Survey Energy Sheet", vbYesNo + vbInformation, "Print Out")
If SiteSurveyEnegy = vbYes Then
With Worksheets("3.0 Site Survey Energy Print")
.Visible = True
.Activate
.Range("A1").Select

With Worksheets("3.0 Site Survey Energy Print").PageSetup
.PrintTitleRows = "$1:$4"
.PrintTitleColumns = ""
.PrintArea = "$A$1:$J$38"
.LeftHeader = ""
.CenterHeader = ""
.RightHeader = ""
.LeftFooter = "Page &P"
.CenterFooter = ""
.RightFooter = "&T &D"
.LeftMargin = Application.InchesToPoints(0.26)
.RightMargin = Application.InchesToPoints(0.26)
.TopMargin = Application.InchesToPoints(0.4)
.BottomMargin = Application.InchesToPoints(0.4)
.HeaderMargin = Application.InchesToPoints(0.3)
.FooterMargin = Application.InchesToPoints(0.3)
.PrintHeadings = False
.PrintGridlines = False
.PrintComments = xlPrintNoComments

.Zoom = 77

End With
.PrintPreview
End With

End If
Exit Sub
ErrorLine:
MsgBox ("Error Number:" & Err.Number & ". " & Err.Description & ". Source:" & Err.Source)

ActiveWorkbook.Close
End Sub
 

Forum statistics

Threads
1,081,749
Messages
5,361,064
Members
400,611
Latest member
ThebigG

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top