A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » New Users
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

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



 
 
Thread Tools Display Modes
  #1  
Old February 14th, 2006, 05:25 PM posted to microsoft.public.access.gettingstarted
external usenet poster
 
Posts: n/a
Default How do I use a command button to open an excel file?

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.
  #2  
Old February 14th, 2006, 06:09 PM posted to microsoft.public.access.gettingstarted
external usenet poster
 
Posts: n/a
Default How do I use a command button to open an excel file?

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

"Justin" wrote:

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.

  #3  
Old February 14th, 2006, 06:23 PM posted to microsoft.public.access.gettingstarted
external usenet poster
 
Posts: n/a
Default How do I use a command button to open an excel file?

On Tue, 14 Feb 2006 09:25:27 -0800, Justin wrote:

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"
--
Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail
 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to open MS Excel 2000 version9 file from Windows XE folder juliet.mart General Discussions 4 October 20th, 2005 03:59 PM
Multi-User vs Client/Server GeorgieGirl General Discussion 3 June 8th, 2005 11:42 PM
.jpg .gif .bmp file associations gone, upgrade from Office XP to 2 fbartrom Setup, Installing & Configuration 13 February 25th, 2005 01:33 PM
You do not have exclusive access... ERROR Robin General Discussion 1 July 6th, 2004 01:18 AM
Cannot open large excel file Niall Caslin Worksheet Functions 3 October 29th, 2003 05:24 PM


All times are GMT +1. The time now is 09:21 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.