VBA Code for a print button

DerekN

New Member
Joined
Sep 16, 2017
Messages
4
I have setting up a siple print button where on initiation the macro prints a range of cells on a speciic worksheet in a workbook. But I have been getting a compile error. I just cannot see whats wrong...any suggestions?

Sub Print_Invoice()
Sheets("PreSchoolInvoice").PrintOut
ActiveSheet.Range("A1:H62").Select
End Sub
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Is it actually a compile error i.e. the line goes red (doesn't for me), if yes what line?
or is it a normal error, if yes again what line and what does the message state?
Do you have any sheet protection?
 
Upvote 0
mmm looking at my code though... the logic is not quite right, so I tried this
Sub Print_Invoice()
Sheets("PreSchoolInvoice").Select
ActiveSheet.Selection("A1:H62").PrintOut
End Sub

and got an error which said "Invalid Outside Procedure" . I do not have protection on the sheet
 
Upvote 0
Invalid outside procedure normally means you have some characters outside the routine, do you? even in another module but your sub is also incorrect in its syntax.

What are you trying to do? print range A1:H62 on Sheet("PreSchoolInvoice")?
 
Upvote 0
I see.. I cannot see anytging outside the routine......I imagine its my syntax. Yes I am trying to print a range on a sheet - print range A1:H62 on Sheet("PreSchoolInvoice")
 
Upvote 0
I cannot see anytging outside the routine......I imagine its my syntax

Your syntax shouldn't produce that error it should produce an Object doesn't support that property or method error anyway....

One code for printing the range is....


Code:
Sub Print_Invoice()
 With Sheets("PreSchoolInvoice")
   .PageSetup.PrintArea = "$A$1:$H$62"
   .PrintOut
 End With
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,241
Members
452,622
Latest member
Laura_PinksBTHFT

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