View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Ron de Bruin Ron de Bruin is offline
external usenet poster
 
Posts: 11,123
Default Detect Workbook Name when using GetOpenFileName

Hi Chris

You can use Dir


Sub testing()
Dim FName As Variant
Dim N As Long
FName = Application.GetOpenFilename(filefilter:="Excel Files (*.xls), *.xls")

If FName < False Then
MsgBox Dir(FName)
End If
End Sub


--
Regards Ron de Bruin
http://www.rondebruin.nl


"Chris Gorham" wrote in message ...
Hi,

I'm using the following code in Access to select an Excel file that I wish
to import into a Table. It works great. However I would also like to test
that the user has selected the correct Excel file.

"directory" provides the file path information that I need for the Access
VBA statement to import the file into the table. However before I go futher I
need to test for the name of the workbook as well. I could parse this out by
detecting the backslashes in the file path - but that's not very neat.

Any help appreciated.

Rgds...Chris

Set xlObj = CreateObject("excel.application")
xlObj.Visible = True

directory = xlObj.Application.getopenfilename("Excel Files (*.XLS),
*.XLS", 1)