Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Path and Name

Hello to all!

Here is my problem: I need to know the name and path of a file that is
selected through "Application.GetOpenFilename()." However whenever I try to
run the code "Run-time error '9': Subscript out of range" message comes up.
I thought that it could be the file path is too long(files on the network)
however when I selected a local file and my hd the same message still came up.

Here is the code:
Private Sub CommandButton1_Click()
Dim file As String, Path1 As String, name As String
file = Application.GetOpenFilename()
Path1 = Workbooks(file).Path
name = Workbooks(file).Name
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Path and Name

That is because the Workbooks collection pertains to OPEN workbooks. Your
code hasn't opened the filename retrieved by GetOpenFilename. Either open it
and use your c ode, or parse it manually.

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"SoSoExcelGuy" wrote in message
...
Hello to all!

Here is my problem: I need to know the name and path of a file that is
selected through "Application.GetOpenFilename()." However whenever I try

to
run the code "Run-time error '9': Subscript out of range" message comes

up.
I thought that it could be the file path is too long(files on the network)
however when I selected a local file and my hd the same message still came

up.

Here is the code:
Private Sub CommandButton1_Click()
Dim file As String, Path1 As String, name As String
file = Application.GetOpenFilename()
Path1 = Workbooks(file).Path
name = Workbooks(file).Name
End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 33
Default Path and Name

Continuing on from Bob's reply:
If you want the file to open then use:

Private Sub CommandButton2_Click()
Dim file As String, Path1 As String, name As String
file = Application.GetOpenFilename()
Workbooks.Open file
Path1 = ActiveWorkbook.Path
name = ActiveWorkbook.name
End Sub

If you don't wnt the file open first, use the split function:

ie file2=split(file,"\")

and then look at all the elements of array file2.

ChasAA

"SoSoExcelGuy" wrote:

Hello to all!

Here is my problem: I need to know the name and path of a file that is
selected through "Application.GetOpenFilename()." However whenever I try to
run the code "Run-time error '9': Subscript out of range" message comes up.
I thought that it could be the file path is too long(files on the network)
however when I selected a local file and my hd the same message still came up.

Here is the code:
Private Sub CommandButton1_Click()
Dim file As String, Path1 As String, name As String
file = Application.GetOpenFilename()
Path1 = Workbooks(file).Path
name = Workbooks(file).Name
End Sub

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Path and Name

Thanks for the help guys!

"ChasAA" wrote:

Continuing on from Bob's reply:
If you want the file to open then use:

Private Sub CommandButton2_Click()
Dim file As String, Path1 As String, name As String
file = Application.GetOpenFilename()
Workbooks.Open file
Path1 = ActiveWorkbook.Path
name = ActiveWorkbook.name
End Sub

If you don't wnt the file open first, use the split function:

ie file2=split(file,"\")

and then look at all the elements of array file2.

ChasAA

"SoSoExcelGuy" wrote:

Hello to all!

Here is my problem: I need to know the name and path of a file that is
selected through "Application.GetOpenFilename()." However whenever I try to
run the code "Run-time error '9': Subscript out of range" message comes up.
I thought that it could be the file path is too long(files on the network)
however when I selected a local file and my hd the same message still came up.

Here is the code:
Private Sub CommandButton1_Click()
Dim file As String, Path1 As String, name As String
file = Application.GetOpenFilename()
Path1 = Workbooks(file).Path
name = Workbooks(file).Name
End Sub

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
File Path Too Long? Not Anymore! Check out Long Path Tool Max Loger Excel Discussion (Misc queries) 1 March 24th 17 07:59 AM
Formula too long - new file path is shorter than old file path - Excel 2003 Greg J Excel Worksheet Functions 1 November 22nd 06 05:16 PM
hyperlink navigation path path wrong in Excel 2003 CE Admin Excel Discussion (Misc queries) 5 January 7th 06 07:47 PM
how to change absolute path to relative path hwijgerse Excel Worksheet Functions 0 November 25th 05 07:18 AM
Current path to Qualified Path Mary Excel Programming 1 October 14th 04 02:42 PM


All times are GMT +1. The time now is 01:20 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"