VBA Code to open Wxcel from within Access

R

Rod Manson

Hi, can anyone help please . . I thought it would be quite straightforward ..

I want to write the code to open an excel spreadsheet from with Access. I
can see how to do it with the RunApp Action in a macro, but not in code.

Thanks!
 
D

Dennis

I asssume you mean the Excel spreadsheet already exists and you want to open
it, Edit it and re-save it ? If Yes, use something like this

Function Open_Excel_File()
On Error GoTo Excel_Error
Dim xlApp As Excel.Application
Dim xlWS As Excel.Worksheet

Set xlApp = New Excel.Application
If xlApp.FindFile = True Then
Set xlWS = xlApp.Worksheets(1)

' your code here to do stuff on the worksheet

xlWS.SaveAs xlApp.ActiveWorkbook.FullName
xlApp.Quit
Set xlWS = Nothing
End If
Set xlApp = Nothing
Exit Function

Excel_Error:
MsgBox Err.Description
xlApp.Quit
Set xlWS = Nothing
Set xlApp = Nothing
End Function
 
S

Stuart McCall

Rod Manson said:
Hi, can anyone help please . . I thought it would be quite straightforward
..

I want to write the code to open an excel spreadsheet from with Access. I
can see how to do it with the RunApp Action in a macro, but not in code.

Thanks!

Application.FollowHyperlink "C:\FolderName\FileName.xls"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top