7 réponses
To respond to Fred:
First, you need to add a reference to Excel to have access to Excel objects. To do this, you need to open a code module and then use the Tools menu, References, and search in the list for: Microsoft Excel 8 (for example).
Then, here is an example of code (for the button cmdOpenExcel):
Private Sub cmdOpenExcel_Click()
Dim xls As Excel.Application
On Error GoTo errHnd
Set xls = CreateObject("Excel.Application")
xls.Workbooks.Open "c:\toto.xls"
xls.Visible = True
Exit Sub
errHnd:
MsgBox "Error No. " & Err.Number & vbLf & Err.Description, , Err.Source
End Sub
First, you need to add a reference to Excel to have access to Excel objects. To do this, you need to open a code module and then use the Tools menu, References, and search in the list for: Microsoft Excel 8 (for example).
Then, here is an example of code (for the button cmdOpenExcel):
Private Sub cmdOpenExcel_Click()
Dim xls As Excel.Application
On Error GoTo errHnd
Set xls = CreateObject("Excel.Application")
xls.Workbooks.Open "c:\toto.xls"
xls.Visible = True
Exit Sub
errHnd:
MsgBox "Error No. " & Err.Number & vbLf & Err.Description, , Err.Source
End Sub
Hello,
The subject is old and I don't know if I will get a response.
The code above works well, except that it opens the Excel file twice...
Does anyone have an idea?
The subject is old and I don't know if I will get a response.
The code above works well, except that it opens the Excel file twice...
Private Sub Bascule65_Click() Dim xls As Excel.Application On Error GoTo errHnd Set xls = CreateObject("Excel.Application") xls.Workbooks.Open "c:\AvisCom\Trimestriel.xls" xls.Workbooks("Trimestriel.xls").Sheets("Feuil2").Activate xls.Visible = True Exit Sub errHnd: MsgBox "Error No. " & Err.Number & vbLf & Err.Description, , Err.Source End Sub Does anyone have an idea?
Hello,
Here is a method that can be used:
Don't forget to reference: Microsoft Excel xx.x Object Library in Tools > References ...
;o)
--
“What is well conceived is clearly expressed, And the words to say it come easily.”
Nicolas Boileau
Here is a method that can be used:
Private Sub Bascule65_Click() Dim xls As Excel.Application Dim wk As Excel.Workbook Dim ws As Excel.Worksheet On Error GoTo errHnd Set xls = CreateObject("Excel.Application") Set wk = xls.Workbooks.Open("C:\AvisCom\Trimestriel.xls") Set ws = wk.Sheets("Feuil2") ws.Activate xls.Visible = True Exit Sub errHnd: MsgBox "Error No. " & Err.Number & vbLf & Err.Description, , Err.Source End Sub Don't forget to reference: Microsoft Excel xx.x Object Library in Tools > References ...
;o)
--
“What is well conceived is clearly expressed, And the words to say it come easily.”
Nicolas Boileau
Hello
There is a very simple way: create a button using the assistant: it’s a button from the Application category and the action is Run Microsoft Excel. The assistant will create the code to open Excel for you.
For the assistant to be active, the second button on the toolbar must be pressed down (the one after the arrow).
You can obviously do much better by opening a specific file or controlling Excel from ACCESS with VBA code. This is called OLE Automation.
Good luck
Michel
There is a very simple way: create a button using the assistant: it’s a button from the Application category and the action is Run Microsoft Excel. The assistant will create the code to open Excel for you.
For the assistant to be active, the second button on the toolbar must be pressed down (the one after the arrow).
You can obviously do much better by opening a specific file or controlling Excel from ACCESS with VBA code. This is called OLE Automation.
Good luck
Michel