I have a requirement to open and xls file from access vba so users can change or just peruse the book.
In vba i have created the xls file using TransferSpreadsheet, i then have code to create a heading.
What i now need to do is to open the xls file for the user.
How to do this?
Open an xls file inside access vba
-
- Administrator
- Posts: 78474
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Open an xls file inside access vba
Copy the following code into a standard module. It must go before all Subs and Functions:
To open the workbook from your code:
where strFullName is a string variable holding the path and filename of the workbook that you created.
If you'd prefer Excel to be opened in a maximized window, change SW_SHOWNORMAL to SW_SHOWMAXIMIZED.
Code: Select all
Public Declare Function ShellExecute _
Lib "shell32.dll" Alias "ShellExecuteA" ( _
ByVal hwnd As Long, _
ByVal lpOperation As String, _
ByVal lpFile As String, _
ByVal lpParameters As String, _
ByVal lpDirectory As String, _
ByVal nShowCmd As Long) As Long
Public Const SW_SHOWNORMAL = 1
Public Const SW_SHOWMAXIMIZED = 3
Code: Select all
ShellExecute Application.hWndAccessApp, "Open", _
strFullName, 0&, 0&, SW_SHOWNORMAL
If you'd prefer Excel to be opened in a maximized window, change SW_SHOWNORMAL to SW_SHOWMAXIMIZED.
Best wishes,
Hans
Hans
-
- 5StarLounger
- Posts: 1148
- Joined: 08 Feb 2010, 21:27
Re: Open an xls file inside access vba
Thank you Hans, it works well
-
- NewLounger
- Posts: 6
- Joined: 04 Mar 2012, 16:40
Re: Open an xls file inside access vba
Thanks Mr. HansV