We help IT Professionals succeed at work.

open an Excel File through a button on the form in MS Access 2007

FinghtingMiao
on
I am working on MS Access Forms.
I created a form , and now I was asked to add a new button. If click on the button, then should able to open an Excel spreadsheet which the client sent to me. (just one excel spreadsheet)

Basicallty they are asking to attach a excel spreadsheet to the form, and it could be opened by clicking on a button.

How should we do this? Import this excel first ? and write a macros?
or some other method?

Thanks.

Comment
Watch Question

Owner, Dev-Soln LLC
Most Valuable Expert 2014
Top Expert 2010
Commented:
Depends on what you want to do with it.

If you know the name of the file, you could just use the application.followhyperlink method to open the file:

Private sub cmd_Excel_Click

    application.followhyperlink "C:\Filename.xlsx"

End sub

Or if the name of the file will change, you could use the FileOpenSave API call to open the file Open/Save dialog box.  Examples of that code are available at:  access.mvps.org/access/api/api0001.htm (although it looks like that site is down at the moment).  You could then use the followhyperlink method to open the file.

Or, you could link to the excel file and display it for your users in an access form (datasheet or continuous).
Sorry, I am a little confused by your requirements.

Does this single Microsoft Excel workbook exist in a pre-defined (& fixed) location in your local or network filing system?

Or, is the filename of the file stored in a field in your Microsoft Access form (&/or underlying database table)?

Either way, do you just wish to launch MS-Excel externally to your MS-Access application with the specified workbook file shown, or do you wish to show the contents of one/more worksheets within the MS-Access form?

Thank you for your clarification.

For further background on "launching" MS-Excel from the MS-Windows association to a given filename extension (".xls", ".xlsm", & so on), please see my comment ("02/03/04 09:29 AM, ID: 10493462") in this thread:

[http://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/MS_Office/Excel/Q_20903550.html ]

Here a file with the extension ".mpg" is opened in the associate MS-Windows application.

BFN,

fp.
In the button's Click Event enter this code:

Application.FollowHyperlink this_filePath, , True

Open in new window


Where this_filePath is a variable that holds the filepath of the excel workbook you're trying to open. I think that should work for you.

Good luck!
aebea

Author

Commented:
Thank you very much for you solution. They are all very helpful and my issue resolved.

Thank you.
You're very welcome.

Thank you for your closing comment.