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

Here's my example:

Book = Application.GetOpenFilename
Set Rng = Workbooks(Book).Worksheet("Sheet1").Range("A1")

It results in error because GetOpenFilename returns a full file path, not
file name.
Is there a way to solve this?

Thanks
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 694
Default GetOpenFilename

GetOpenFileName returns a string, but does not open the chosen book, you
have to do it yourself:

Dim f As String
Dim wkb As Workbook
Dim Rg As Range

f = Application.GetOpenFilename()
If f = "False" Then
MsgBox "Cancelled by user"
Exit Sub
End If

Set wkb = Workbooks.Open(f)
Set Rg = wkb.Worksheet("Sheet1").Range("A1")

Regards,
Sebastien

"Roman" wrote:

Here's my example:

Book = Application.GetOpenFilename
Set Rng = Workbooks(Book).Worksheet("Sheet1").Range("A1")

It results in error because GetOpenFilename returns a full file path, not
file name.
Is there a way to solve this?

Thanks

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 694
Default GetOpenFilename

one more thing: to prevent user from choosing non-excel files, you could use
f = Application.GetOpenFilename("Excel Files (*.xls),*.xls")
This will only show xls files.
Sebastien

"sebastienm" wrote:

GetOpenFileName returns a string, but does not open the chosen book, you
have to do it yourself:

Dim f As String
Dim wkb As Workbook
Dim Rg As Range

f = Application.GetOpenFilename()
If f = "False" Then
MsgBox "Cancelled by user"
Exit Sub
End If

Set wkb = Workbooks.Open(f)
Set Rg = wkb.Worksheet("Sheet1").Range("A1")

Regards,
Sebastien

"Roman" wrote:

Here's my example:

Book = Application.GetOpenFilename
Set Rng = Workbooks(Book).Worksheet("Sheet1").Range("A1")

It results in error because GetOpenFilename returns a full file path, not
file name.
Is there a way to solve this?

Thanks

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,758
Default GetOpenFilename

Until the user types:
*.*
in the filename box in that dialog.



sebastienm wrote:

one more thing: to prevent user from choosing non-excel files, you could use
f = Application.GetOpenFilename("Excel Files (*.xls),*.xls")
This will only show xls files.
Sebastien

"sebastienm" wrote:

GetOpenFileName returns a string, but does not open the chosen book, you
have to do it yourself:

Dim f As String
Dim wkb As Workbook
Dim Rg As Range

f = Application.GetOpenFilename()
If f = "False" Then
MsgBox "Cancelled by user"
Exit Sub
End If

Set wkb = Workbooks.Open(f)
Set Rg = wkb.Worksheet("Sheet1").Range("A1")

Regards,
Sebastien

"Roman" wrote:

Here's my example:

Book = Application.GetOpenFilename
Set Rng = Workbooks(Book).Worksheet("Sheet1").Range("A1")

It results in error because GetOpenFilename returns a full file path, not
file name.
Is there a way to solve this?

Thanks


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 694
Default GetOpenFilename

very true, Dave.
Sebastien


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 226
Default GetOpenFilename

Application.GetOpenFilename doesn't open the file, it just returns the
filename that the user chose OR False, if the user canceled.

Is the book open when you try to assign the range ? if so, then you don't
need GetOpenFileName, if its not, then try

Set Rng = Workbooks.Open(Book).Worksheets("Sheet1").Range("A 1")

--
Regards

Juan Pablo González

"Roman" wrote in message
...
Here's my example:

Book = Application.GetOpenFilename
Set Rng = Workbooks(Book).Worksheet("Sheet1").Range("A1")

It results in error because GetOpenFilename returns a full file path, not
file name.
Is there a way to solve this?

Thanks



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
GetOpenFilename Jenny Excel Programming 2 October 22nd 04 01:38 PM
GetOpenFilename Todd Htutenstine Excel Programming 2 May 13th 04 03:14 PM
getopenfilename inquirer Excel Programming 1 December 3rd 03 11:37 AM
GetOpenFilename Hasan Cansü Excel Programming 0 September 24th 03 01:32 PM
Using GetOpenFilename Robin Seaby Excel Programming 2 August 6th 03 04:50 PM


All times are GMT +1. The time now is 10:33 PM.

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

About Us

"It's about Microsoft Excel"