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

How to open an excel worksheet from Access VBA

Status
Not open for further replies.

Quigger

Programmer
Jan 9, 2003
3
US
I have a procedure where I open an excel spreadsheet from within Access. I want to be able to open the spreadsheet and then have it go to a specific worksheet, which is dependent on the unit name. I've used the shell command to open the specific spreadsheet, but I can't figure out how to automatically direct it to the worksheet.
Thank you!

Private Sub cmdEscalLink_Click()

Call Shell("Excel.exe \\xorl008\groups\ESD\Fleet_Mon_Diag\Section\groupp~1\escalation.xls", 1)

End Sub
 
Control it from within Access itself with something like the following. You have to have a Tools, References item set to Microsoft Excel whatever for this to work:

Private Sub ProcessExcelFile(pstrPath As String, _
pstrFileName As String)
Dim objXL As Excel.Application
Dim xlWB As Excel.Workbook
Dim xlWS As Excel.Worksheet
Dim intCol As Integer
Dim strTemp As String

Set objXL = CreateObject("Excel.Application")
Set xlWB = objXL.Workbooks.Open(pstrPath & pstrFileName)
Set xlWS = xlWB.Worksheets(1)
objXL.Visible = True
xlWS.Activate

Do something here

'Close Excel without saving anything
xlWB.Close False
objXL.Quit

'Release objects from memory
Set xlWS = Nothing
Set xlWB = Nothing
Set objXL = Nothing
End Sub ' ProcessExcelFile

Good Luck!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top