Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default Detect Workbook Name when using GetOpenFileName

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)
  #2   Report Post  
Posted to microsoft.public.excel.programming
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)



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 860
Default Detect Workbook Name when using GetOpenFileName

Hi Chris,

Here's another way:

Sub test()
Dim vFullPath As Variant
Dim vFileInfo As Variant
Dim sFileName As String

vFullPath = Application.GetOpenFilename("Excel Files " & _
"(*.XLS), *.XLS", 1)

If vFullPath < False Then
MsgBox vFullPath
vFileInfo = Split(vFullPath, Application.PathSeparator)
sFileName = vFileInfo(UBound(vFileInfo))
MsgBox sFileName
End If
End Sub


This is code from within Excel, so you'll have to qualify references to
Application with xlObj.

--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

[please keep replies in the newsgroup - email address unmonitored]


Chris Gorham wrote:
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)


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to hide a workbook and to detect a hidden workbook in visual basic jn1971[_3_] Excel Programming 0 May 5th 04 10:08 PM
Detect macro's parent workbook or worksheet Conceptor[_2_] Excel Programming 1 April 26th 04 10:21 PM
GetOpenFilename Greg Bloom Excel Programming 0 February 9th 04 03:32 PM
Detect workbook events from .XLA Conceptor[_2_] Excel Programming 2 October 27th 03 07:05 PM
Detect more info when workbook does not ack right. Tom Ogilvy Excel Programming 0 July 11th 03 02:34 PM


All times are GMT +1. The time now is 05:56 AM.

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

About Us

"It's about Microsoft Excel"