Connecting Tech Pros Worldwide Help | Site Map

Open Excel File from Access Form using Wildcards

Newbie
 
Join Date: Oct 2009
Posts: 3
#1: 3 Weeks Ago
Hello,

I'm somewhat new to Access and I'm trying to open an Excel file from an Acess form command button. The only problem is the Excel filename includes a date and the date changes on a weekly basis. Is there a code that I can use use that supports wildcards?

Thank you in advance!
Expert
 
Join Date: Jul 2008
Location: Maryland
Posts: 1,158
#2: 3 Weeks Ago

re: Open Excel File from Access Form using Wildcards


As far as I know, you do have to name one specific file to open. You can get the filename easily with the Dir command if you can determine the location of the file.
Newbie
 
Join Date: Oct 2009
Posts: 3
#3: 3 Weeks Ago

re: Open Excel File from Access Form using Wildcards


Thanks for the quick response. I'm sorry - but I'm not familiar with the DIR command. I'm new to this. Can you give me an example using DIR in a code.
Delerna's Avatar
Expert
 
Join Date: Jan 2008
Location: Sydney
Posts: 782
#4: 3 Weeks Ago

re: Open Excel File from Access Form using Wildcards


click on the blue underlined word Dir in chipr's post.
It is a link to all the info you need
ADezii's Avatar
Expert
 
Join Date: Apr 2006
Location: Philadelphia
Posts: 5,212
#5: 3 Weeks Ago

re: Open Excel File from Access Form using Wildcards


Quote:

Originally Posted by brunpam View Post

Hello,

I'm somewhat new to Access and I'm trying to open an Excel file from an Acess form command button. The only problem is the Excel filename includes a date and the date changes on a weekly basis. Is there a code that I can use use that supports wildcards?

Thank you in advance!

You never stated whether or not the location of your Excel File was static or dynamic. In light of this, I wrote comprehensive code that will:
  1. Open the Standard Office File Dialog Window.
  2. This Dialog will only display Excel (*.xls) Files and no other Files.
  3. Once you Navigate to, then select a File, it will then Open it in Excel.
  4. Do not forget to:
    1. Set a Reference to the Microsoft Office XX.X Object Library.
    2. Change the value of the Constant pointing to the Path to Excel.exe, if necessary.
  5. If you decide to use this approach, and need further help, we re here.
Expand|Select|Wrap|Line Numbers
  1. 'First, set a Reference to the Microsoft Office XX.X Object Library
  2.  
  3. Dim strButtonCaption As String
  4. Dim strDialogTitle As String
  5. Dim varFileSelected As Variant
  6. Dim varRetVal As Variant
  7. Const conEXCEL_PATH = "C:\Program Files\Microsoft Office\Office10\EXCEL.EXE"
  8.  
  9. 'Define your own Captions if necessary
  10. strButtonCaption = "&Open"
  11. strDialogTitle = "Select Excel File to Open"
  12.  
  13. With Application.FileDialog(msoFileDialogOpen)
  14.   With .Filters
  15.     .Clear
  16.     .Add "Excel Files", "*.xls"                 'Allow Excel Files only
  17.   End With
  18.   'The Show Method returns True if 1 or more files are selected
  19.     .AllowMultiSelect = False                   'Critical Line
  20.     .ButtonName = strButtonCaption
  21.     .InitialFileName = vbNullString
  22.     .InitialView = msoFileDialogViewDetails     'Detailed View
  23.       .Title = strDialogTitle
  24.   If .Show Then     'File selected
  25.      varFileSelected = .SelectedItems(1)        'Can only be 1 File selected
  26.      'Open the Excel File
  27.      varRetVal = Shell(conEXCEL_PATH & " " & Chr(34) & varFileSelected & Chr(34), vbMaximizedFocus)
  28.   End If
  29. End With
maxamis4's Avatar
Expert
 
Join Date: Jan 2007
Location: Northern VA
Posts: 214
#6: 3 Weeks Ago

re: Open Excel File from Access Form using Wildcards


If you are new to Access you want simple. The best way is to go to the button properties and under On Click paste this code. All you will have to do is change the path, the directory where the excel sheet is located.

Additionally in the code page of Access you will need to go to tools >>Reference
Select the following object library. This step you will have to do for any of the code examples provided. "Microsoft Excel xx.0 Library" xx version of excel, pick the latest.

Expand|Select|Wrap|Line Numbers
  1. use xlApp.Workboks.Open
  2.  
  3. Dim xlApp As Excel.Application
  4. Dim xlWB1 As Excel.Workbook
  5.  
  6.    Set xlApp = New Excel.Application
  7.  
  8.    xlApp.Visible = True
  9.  
  10.    Set xlWB1 = xlApp.Workbooks.Open("e:\paige\vb program\delinquent.xls")
  11.  
  12.    xlWB1.Close
  13.  
  14. Set xlWB1 = Nothing
  15.  
  16.    xlApp.Quit
  17.  
  18. Set xlApp = Nothing
  19.  
  20.  
Newbie
 
Join Date: Oct 2009
Posts: 3
#7: 3 Weeks Ago

re: Open Excel File from Access Form using Wildcards


Thank you all for your quick response!
Reply


Similar Microsoft Access / VBA bytes