
Opening an excel file through a form/running excel macros through access
still not clear if the code below was to open an excel
book and/or to run a macaro within it. Ideally would
like seperate code. Aslo, is this code in excel vba or
access vba?
I have a button which opens excel (but no file) the code
is
Private Sub OpenExcel_Click()
On Error GoTo Err_OpenExcel_Click
Dim oApp As Object
Set oApp = CreateObject("Excel.Application")
oApp.Visible = True
'Only XL 97 supports UserControl Property
On Error Resume Next
oApp.UserControl = True
Exit_OpenExcel_Click:
Exit Sub
Err_OpenExcel_Click:
MsgBox Err.Description
Resume Exit_OpenExcel_Click
End Sub
Ideally I would like 3 buttons
1. to open excel (already done)
2. open a specific file
3. once the file is open have a button to run an excel
macro from a access form.
any help would be greatly appreciated
Quote:
>-----Original Message-----
>Here's some sample code for opening an EXCEL workbook
and running a VBA
>macro that's in the workbook in a public module:
>Public Sub TestMacroRun()
>Dim xlx As Object, xlw As Object
>Set xlx = CreateObject("excel.application")
>Set xlw = xlx.workbooks.Open("C:\Filename.xls")
>xlx.Run "Filename.xls!MacroName()"
>xlw.Close False
>xlx.Quit
>Set xlw = Nothing
>Set xlx = Nothing
>End Sub
>--
> Ken Snell
><MS ACCESS MVP>
>> I have a form with a "start excel button" but I cant
>> figure how to then get a particular file open. I tried
>> adding code to the module as I would in VBA in excel
but
>> didnt work. Any ideas??
>> Also, is there a way to run an excel macro from an
>> access form after the excel file is opened? I have a
>> macro which refreshes the links from access into excel.
>.