Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to print Excel worksheet from Access 2007

Posted on 2014-02-03
3
Medium Priority
?
468 Views
Last Modified: 2014-02-04
Similar questions here at the exchange offered (aging) solutions which I couldn't make work, so I thought I'd get the latest.  I simply need to print a spreadsheet; I don't need to link it to the database, and it has never been linked to the db.
0
Comment
Question by:David_W_R
3 Comments
 
LVL 25

Accepted Solution

by:
chaau earned 1600 total points
ID: 39830896
You can use a bit of VBA code for that:
Dim xlTmp As Object
Set xlTmp = CreateObject("Excel.Application")
xlTmp.Visible = False
Dim xlWbk As Object
Set xlWbk = xlTmp.Workbooks.Open("C:\Excel1.xls")
xlWbk.PrintOut
xlWbk.Close SaveChanges:=False
xlTmp.Quit
Set xlTmp = Nothing

Open in new window

0
 
LVL 120

Assisted Solution

by:Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1) earned 400 total points
ID: 39830927
try this codes


Dim xlobj As Object, xlFile As String
xlFile = CurrentProject.Path & "\TestFile.xlsx"
Set xlobj = CreateObject("excel.application")
     xlobj.Workbooks.Open xlFile
     xlobj.Worksheets("sheet2").Select
     xlobj.Worksheets("sheet2").PrintOut
     xlobj.Quit
0
 

Author Closing Comment

by:David_W_R
ID: 39833603
chaau, your method worked flawlessly; just had to add add "ActiveSheet" to the command.
Rey Obrero, your method appears similar, but I didn't have time to check it.  Either way, it has a couple of items that will help me understand more about this subject.  Thank you both for the timely response.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
In a use case, a user needs to close an opened report by simply pressing the Escape (Esc) key. This can be done by adding macro code in Report_KeyPress or Report_KeyDown event.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

916 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