+ Reply to Thread
Results 1 to 6 of 6

Conflict with GetOpenFilename and Workbooks(x).Close - expected filename and not path

  1. #1
    Registered User
    Join Date
    07-03-2012
    Location
    Norge
    MS-Off Ver
    Excel 2010
    Posts
    40

    Conflict with GetOpenFilename and Workbooks(x).Close - expected filename and not path

    Hi everyone,

    I have some issues when opening a file with the GetOpenFilename method, and then trying to close it later, with Application.Workbooks(x).Close.

    Basically, this is what I'm trying to accomplish:

    Please Login or Register  to view this content.
    The issue here is that the GetOpenFilename method gets the whole path of the file, while the Application.Workbooks(x).Close method expects only the file name, and not the whole path.
    Therefore I get run-time error '9', Subscript out of range.

    What would be the best way to get around this?
    Should I use another method to open the file, or should i create a variable that extracts the filename from the whole path, and puts it into a new variable?

    Your suggestions are really appreciated!

    Best regards,
    Knut

  2. #2
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Conflict with GetOpenFilename and Workbooks(x).Close - expected filename and not path

    use a workbook variable
    Please Login or Register  to view this content.
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  3. #3
    Registered User
    Join Date
    07-03-2012
    Location
    Norge
    MS-Off Ver
    Excel 2010
    Posts
    40

    Re: Conflict with GetOpenFilename and Workbooks(x).Close - expected filename and not path

    Quote Originally Posted by JosephP View Post
    use a workbook variable
    Please Login or Register  to view this content.
    I'm now able to close the file, but now the semicolon separation of the csv file does not work anymore.
    Can't seem to get it working with the original version i posted either - but I'm really sure it worked before...

  4. #4
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Conflict with GetOpenFilename and Workbooks(x).Close - expected filename and not path

    I reckon you had the argument in the wrong place-easier to name them
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    07-03-2012
    Location
    Norge
    MS-Off Ver
    Excel 2010
    Posts
    40

    Re: Conflict with GetOpenFilename and Workbooks(x).Close - expected filename and not path

    I figured it out. Had to set Local to True, like this:
    Please Login or Register  to view this content.

  6. #6
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Conflict with GetOpenFilename and Workbooks(x).Close - expected filename and not path

    the delimiter argument is ignored unless format:=6
    did you try setting format:=4 which specifies the semicolon separator?

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 3
    Last Post: 07-09-2012, 03:09 PM
  2. How to close open workbooks from an application get open filename call ?
    By leanne2011 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-10-2011, 10:41 PM
  3. how to close a file opened with "Workbooks.Open Filename:=sWb"
    By ggremel in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-07-2011, 10:37 PM
  4. Find filename, path, document size, filename length and path length?
    By Laneyboggs in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-30-2010, 08:01 PM
  5. Filter Alphanumeric filename in GetOpenFilename
    By akr in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-05-2008, 11:47 AM

Tags for this Thread

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