Opening an Excel file from VBA code

Solved
TraderAS Posted messages 119 Status Membre -  
pijaku Posted messages 13513 Registration date   Status Modérateur Last intervention   -
Hello,

I want to open an Excel file using the following code:

Sub Ouvrir()
Workbooks.Open Filename:="C:\Documents and Settings\Administrateur\Bureau\TRADING\Action.xlsx"
End Sub

However, when I run it, I get this error
==> Incorrect statement outside of a procedure, and it highlights this part in blue:
C:\Documents and Settings\Administrateur\Bureau\TRADING\Action.xlsx

Thank you.

2 réponses

pijaku Posted messages 13513 Registration date   Status Modérateur Last intervention   2 771
 
Hello,

In VBA Excel, try this:
Sub Open() Dim Path As String, FileName As String Path = "C:\Documents and Settings\Administrator\Desktop\TRADING\" FileName = "Action.xlsx" Workbooks.Open Filename:= Path & FileName End Sub

Sources
--
Best regards,
Franck P
10