?
Solved

VBA Printing

Posted on 2003-03-31
4
Medium Priority
?
343 Views
Last Modified: 2010-05-03
Hi Everyone, I am having problems printing in VBA. Here is my code

MsgBox "Information on purchase " & vbCrLf & vbCrLf & "Total cost:" & vbCrLf & vbCrLf & " £" & Cells(29, 3) & vbCrLf & vbCrLf & "Duration:" & vbCrLf & vbCrLf & Cells(7, 8) & vbCrLf & vbCrLf & "Car:" & vbCrLf & vbCrLf & Cells(5, 8)
Printer.Print "Receipt of Rent"
Printer.Print ""
Printer.EndDoc

However nothing prints, i get a "object required" error. The print code seems to work in VB, but not VBA. Can anyone help?

Any help is appreciated.

Dave
0
Comment
Question by:Helix
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 2

Expert Comment

by:AKbor75
ID: 8237366
some VB objects are not available in VBA, like the printer and screen object.
you'll have to accomplish that different way.
(e.g. put it on a excel sheet/wordt doc and print that.)
0
 

Author Comment

by:Helix
ID: 8237635
Hi all, i still yet have to get printing working in VBA, here is my code so far. I have made a user form for the receipt:

MsgBox "Information on purchase " & vbCrLf & vbCrLf & "Total cost:" & vbCrLf & vbCrLf & " £" & Cells(29, 3) & vbCrLf & vbCrLf & "Duration:" & vbCrLf & vbCrLf & Cells(7, 8) & vbCrLf & vbCrLf & "Car:" & vbCrLf & vbCrLf & Cells(5, 8)
UserForm1.lblcar.Caption = Cells(5, 8)
UserForm1.lblDuration.Caption = Cells(7, 8)
UserForm1.lblTotalcost.Caption = "£ " & Cells(29, 3)
UserForm1.Show
UserForm1.printform
Printer.EndDoc

When the userform is shown, the correct values are shown, however when it's printed, nothing is in the labels. They have no caption by default.
0
 
LVL 2

Accepted Solution

by:
AKbor75 earned 75 total points
ID: 8241449
as you have all data on a sheet, why don't you format that sheet and print it. works great as you have many formatting options.
0
 

Expert Comment

by:CleanupPing
ID: 8531281
Hi Helix,
This old question (QID 20568496) needs to be finalized -- accept an answer, split points, or get a refund.  Please see http://www.cityofangels.com/Experts/Closing.htm for information and options.
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question