Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / New Users / February 2006

Tip: Looking for answers? Try searching our database.

How do I use a command button to open an excel file?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Justin - 14 Feb 2006 17:25 GMT
I am trying to open a specific excel file using a command button in a form.  
I have tried several steps but keep getting an error.
Ken Sheridan - 14 Feb 2006 18:09 GMT
Justin:

There are various ways you could do it.  If you want to manipulate the
contents of the workbook from within Access you'd use automation so that you
can return a reference to the workbook in your Access application.  If you
just want to open the Excel file, however, you can use the VBA Shell function
(check it out in Help).  Or you can call the Widows API ShellExecute
function.  I find this last copes with many 'associated' file types which the
Shell function doesn't handle well.  Put the following module in your
application:

''''module starts''''
Option Compare Database
Option Explicit

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 nshowcm As Long)

Sub ShellToFile(strPath As String, ByVal lngHwnd As Long)

   Dim lngRetVal As Long
   
   lngRetVal = ShellExecute(lngHwnd, "open", strPath, _
       vbNullString, CurDir, 1)
       
   If lngRetVal < 32 Then
       MsgBox "Unable to open file " & strPath, vbInformation, "Warning"
   End If
   
End Sub
''''module ends''''

You can then call it in the button's Click event procedure with:

Dim strPath As String

strPath = < get the path to the Excel file from somewhere>

ShellToFile strPath, hwnd

Ken Sheridan
Stafford, England

> I am trying to open a specific excel file using a command button in a form.  
> I have tried several steps but keep getting an error.
fredg - 14 Feb 2006 18:23 GMT
> I am trying to open a specific excel file using a command button in a form.  
> I have tried several steps but keep getting an error.

Easiest way is to code the Command Button click event:
Application.FollowHyperlink "PathToFolder\SpreadsheetName.xls"
Signature

Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.