Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Access VBA code to print excel chart not working

Status
Not open for further replies.

daddypost

Technical User
Oct 21, 2004
98
US
Here is the code I have:
Public Function openexcel()
Dim xl As Excel.Application
Dim sheet2 As Object
Dim workbook As Object

Set xl = CreateObject("excel.Application")

xl.Workbooks.Open ("C:\last eight periods chart.xls") ' substitute your file here
xl.Visible = True
xl.DisplayAlerts = False
xl.ActiveWorkbook.RefreshAll
Set sheet2 = xl.ActiveWorkbook.Sheets("chart1")
sheet2.printout , , , , , , , "c:\chart.pdf"

It keeps wanting to open the acrobat viewer once the chart has been printed? Is there a way to stop this from happening? Thanks
 
Change this line
sheet2.printout , , , , , , , "c:\chart.pdf"
to this:
sheet2.printout

and that will solve your problem. You're telling Excel to print sheet2 to C:\chart.pdf, and it's going to open the default PDF viewer every time ... :)

HTH


Greg

"for me, the action is the juice.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top