Opening an Excel file from VBA code
Solved
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.
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 answers
-
ModeratorHello,
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