+ Reply to Thread
Results 1 to 7 of 7

GetOpenFilename

  1. #1
    Roman
    Guest

    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. #2
    Registered User
    Join Date
    02-01-2005
    Posts
    3
    Not sure if this would apply to your code in particular, but have you thought of using:

    Thisworkbook.Worksheets("sheet1").range("A1")

  3. #3
    sebastienm
    Guest

    RE: 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


  4. #4
    sebastienm
    Guest

    RE: 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


  5. #5
    Dave Peterson
    Guest

    Re: 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

  6. #6
    sebastienm
    Guest

    Re: GetOpenFilename

    very true, Dave.
    Sebastien

  7. #7
    Juan Pablo González
    Guest

    Re: 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("A1")

    --
    Regards

    Juan Pablo González

    "Roman" <Roman@discussions.microsoft.com> wrote in message
    news:B6D55913-1EE5-4396-8F63-AA43D23589C9@microsoft.com...
    > 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 to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1