How to print a defined named range with command button

RJSIGKITS

Board Regular
Joined
Apr 15, 2013
Messages
109
Hi Guys.

I Have a sheet ("Quote") that I need to add a CommandButton to to print out a range that I have set as a print area.
The sheet itself will have numerous named ranges that need to print independently of each other according to what is needed.

So, at this time all I need to know is:

I have a Print Area Defined called "QuotePrint"
I Have a "CommandButton3"

I want to click the button, and it print only the defined "QuotePrint" area.

What should I change this to to do this, please?

Code:
Private Sub CommandButton3_Click()ThisWorkbook.Sheets("Quote").PrintPreview
End Sub

I will then need to have another button on a different sheet ("Home") to print off another range from the same "Quote" sheet that will print off a "SupplierOrderLog_Print" named range from the "Quote" sheet...

Any help comes with bucket loads of gratitude!
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Try

Code:
Private Sub CommandButton3_Click()
Range("QuotePrint").PrintPreview
End Sub
 
Upvote 0
Try

Code:
Private Sub CommandButton3_Click()
Range("QuotePrint").PrintPreview
End Sub

D'oh!....
Specifying the range was the bit I was missing!... even though it is blatantly for a range! :rolleyes:
What a muppet, I am...

Thanks for the help!
 
Upvote 0
Try

Code:
Private Sub CommandButton3_Click()
Range("QuotePrint").PrintPreview
End Sub

Hi again...

I've just realised that the section that needs to be printed from the "Home" Sheet, needs to be hidden on the "Quote" sheet, and so, will need to be unhidden to print, then hidden again once the print is complete.

So, I need to add this:
Code:
ThisWorkbook.Sheets("Quote").Range("SupplierOrderLog_Print").PrintPreview

Into this:
Code:
Private Sub CommandButton11_Click()Dim pword As String
pword = InputBox("Password Required", "Password Required", "Type Password")
If pword <> "password" Then
MsgBox "Password Mismatch" & vbCr & "Please try again.", vbExclamation + vbOKOnly, "Error"
Exit Sub
Else
Sheets("Quote").Unprotect Password:="password"
If Columns("J:Q").Hidden = True Then
Columns("J:Q").Hidden = False
Else
Columns("J:Q").Hidden = True
End If
Sheets("Quote").Protect Password:="password"
End If
End Sub

J:Q are the Columns that contain my "SupplierOrderLog" Defined Print Area..

Any ideas?..
 
Upvote 0
Maybe (untested)

Code:
Private Sub CommandButton11_Click()
Dim pword As String
Dim hid As Boolean
pword = InputBox("Password Required", "Password Required", "Type Password")
If pword <> "password" Then
    MsgBox "Password Mismatch" & vbCr & "Please try again.", vbExclamation + vbOKOnly, "Error"
    Exit Sub
Else
    Sheets("Quote").Unprotect Password:="password"
    If Columns("J:Q").Hidden = True Then
        Columns("J:Q").Hidden = False
    Else
        Columns("J:Q").Hidden = True
    End If
    hid = Columns("J:Q").Hidden
    Columns("J:Q").Hidden = False
    Range("SupplierOrderLog_Print").PrintPreview
    Columns("J:Q").Hidden = hid
    Sheets("Quote").Protect Password:="password"
End If
End Sub
 
Upvote 0
Maybe (untested)

Code:
Private Sub CommandButton11_Click()
Dim pword As String
Dim hid As Boolean
pword = InputBox("Password Required", "Password Required", "Type Password")
If pword <> "password" Then
    MsgBox "Password Mismatch" & vbCr & "Please try again.", vbExclamation + vbOKOnly, "Error"
    Exit Sub
Else
    Sheets("Quote").Unprotect Password:="password"
    If Columns("J:Q").Hidden = True Then
        Columns("J:Q").Hidden = False
    Else
        Columns("J:Q").Hidden = True
    End If
    hid = Columns("J:Q").Hidden
    Columns("J:Q").Hidden = False
    Range("SupplierOrderLog_Print").PrintPreview
    Columns("J:Q").Hidden = hid
    Sheets("Quote").Protect Password:="password"
End If
End Sub

Thanks for the quick response.
It's not liking this though, throwing up a 1004 run-time error of "Method 'Range' of Object '_Worksheet' Failed"
 
Upvote 0
Maybe (untested)

Code:
Private Sub CommandButton11_Click()
Dim pword As String
Dim hid As Boolean
pword = InputBox("Password Required", "Password Required", "Type Password")
If pword <> "password" Then
    MsgBox "Password Mismatch" & vbCr & "Please try again.", vbExclamation + vbOKOnly, "Error"
    Exit Sub
Else
    Sheets("Quote").Unprotect Password:="password"
    If Columns("J:Q").Hidden = True Then
        Columns("J:Q").Hidden = False
    Else
        Columns("J:Q").Hidden = True
    End If
    hid = Columns("J:Q").Hidden
    Columns("J:Q").Hidden = False
    Range("SupplierOrderLog_Print").PrintPreview
    Columns("J:Q").Hidden = hid
    Sheets("Quote").Protect Password:="password"
End If
End Sub

I tried changing "Range("SupplierOrderLog_Print").PrintPreview"
to
"ThisWorkbook.Sheets("Quote").Range("SupplierOrderLog_Print").PrintPreview"
but this then shows a blank print preview sheet (Like it's still hidden)...
 
Upvote 0
I've tested this with the button on the Quote sheet, starting with the columns unhidden and hidden, and in both cases I don't get any error and the printpreview works as expected.

Is there any event code like Worksheet_Change on that sheet?
 
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,693
Members
448,979
Latest member
DET4492

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