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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Print and/or Open Excel File From Access 1

Status
Not open for further replies.

RonMcNatt

Technical User
May 22, 2002
32
US
I am trying to print a specific Excel file from an Access Form Button and am having problems with the VBA Code.

Also, I am trying to open a specific Excel file from Acesss. I can do it with Word, but am somehow missing the conversion to excel.

Private Sub Open_Word_File_to_Print_Click()
On Error GoTo Err_Open_Word_File_to_Print_Click
Dim objWord As Object 'Word.Document
Dim objstr As String
objstr = "d:\data\word\hw2.doc"

Set objWord = GetObject(objstr, "Word.Document")
objWord.Application.Visible = True
objWord.Application.Documents.Open FileName:=objstr
'Only XL 97 supports UserControl Property
On Error Resume Next
objWord.UserControl = True
Exit_Open_Word_File_to_Print_Click:
Exit Sub
Err_Open_Word_File_to_Print_Click:
MsgBox Err.Description
Resume Exit_Open_Word_File_to_Print_Click
End Sub

Thanks in advance for the help
 
This should open the Excel file print the sheet you specify.

You will need to set the following reference from the Tools References... menu before you can use this code.

'Microsoft Excel 9.0 Object Library

Hope it is of help



Private Sub Command0_Click()
Dim xlApp As Object
Dim xlWB As Workbook
Set xlApp = CreateObject("Excel.Application")
xlApp.AskToUpdateLinks = False
xlApp.DisplayAlerts = False
'Uncomment the next line if you want to view the file
'xlApp.Visible = True

Set xlWB = xlApp.Workbooks.Open("C:\Development\TEST\Test.xls", False)
xlWB.Sheets("Sheet1").Select
xlWB.PrintOut

xlWB.Saved = True
xlApp.AskToUpdateLinks = True
xlApp.DisplayAlerts = True
xlWB.Close
Set xlApp = Nothing



End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top