Opening Files from an access form

R

Richard123

I am trying to create a feature so that the user can enter a file name(an
excel file) and the file opens. I am able to open pre-defined files using the
runapp macro function but i want the user to enter the file name hopefully
without the extention. The excel files that i need to open all exist in one
folder. I was hoping for a form with a text box and a command button so the
user could enter say "book3" and click the command botton and the file to open
 
D

David Lloyd

Richard:

One alternative to open an Excel file would look like the following:

Function OpenExcelFile()

Dim xlapp As New Excel.Application
Dim wkb As New Excel.Workbook
Dim strPath As String

On Error GoTo Errorhandler

strPath = "h:\testbase.xls" 'Put textbox value here

Set wkb = xlapp.Workbooks.Open(strPath)
xlapp.Visible = True
AppActivate "testbase.xls", True

Function_Exit:
Set wkb = Nothing
Set xlapp = Nothing

Exit Function

Errorhandler:
If Err.Number <> 0 Then
MsgBox "Error Number: " & Err.Number & vbCrLf & "Description: " &
Err.Description
Resume Function_Exit
End If
End Function

If you want the user to be able to choose the filename, you can consider
using the FileDialog object. You can find more information on how to use
this object here:

http://support.microsoft.com/default.aspx?scid=kb;en-us;824272

Obviously, you will need a reference to the Excel Object library for the
code to run properly.

--
David Lloyd
MCSD .NET
http://LemingtonConsulting.com

This response is supplied "as is" without any representations or warranties.


I am trying to create a feature so that the user can enter a file name(an
excel file) and the file opens. I am able to open pre-defined files using
the
runapp macro function but i want the user to enter the file name hopefully
without the extention. The excel files that i need to open all exist in one
folder. I was hoping for a form with a text box and a command button so the
user could enter say "book3" and click the command botton and the file to
open
 
Top