Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 348
  • Last Modified:

VBA Printing

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
Helix
Asked:
Helix
  • 2
1 Solution
 
AKbor75Commented:
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
 
HelixAuthor Commented:
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
 
AKbor75Commented:
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
 
CleanupPingCommented:
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now