Open an xls file inside access vba

Pat
5StarLounger
Posts: 1148
Joined: 08 Feb 2010, 21:27

Open an xls file inside access vba

Post by Pat »

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?

User avatar
HansV
Administrator
Posts: 78474
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Open an xls file inside access vba

Post by HansV »

Copy the following code into a standard module. It must go before all Subs and Functions:

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
To open the workbook from your code:

Code: Select all

    ShellExecute Application.hWndAccessApp, "Open", _
        strFullName, 0&, 0&, SW_SHOWNORMAL
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.
Best wishes,
Hans

Pat
5StarLounger
Posts: 1148
Joined: 08 Feb 2010, 21:27

Re: Open an xls file inside access vba

Post by Pat »

Thank you Hans, it works well

Murat OSMA
NewLounger
Posts: 6
Joined: 04 Mar 2012, 16:40

Re: Open an xls file inside access vba

Post by Murat OSMA »

Thanks Mr. HansV
Www.ExcelVBA.Net - Msn Messenger: muratosma@excelvba.net