+ Reply to Thread
Results 1 to 9 of 9

Activate file with date name

  1. #1
    Registered User
    Join Date
    04-13-2004
    Posts
    74

    Activate file with date name

    I have mulitple files, all with date names that vary. The format produces names like Nov 21.xlsx.

    From another file I need to go to the date named file to refresh a pivot. I've tried the code below and keep getting a run time error 9. "Script out of range."

    From the locals window these are the expressions and they are correct:
    : sPath : "C:\Users\clwillis\Desktop" : String
    : WorkbookName : "sPath\Nov 21.xlsx" : String

    This is the code:

    Please Login or Register  to view this content.

    The code stops at the fourth line from bottom: Windows("WorkbookName").Activate

    Any ideas what's wrong?

    Thanks, Cliff
    Last edited by Lift Off; 11-29-2011 at 08:35 PM.

  2. #2
    Registered User
    Join Date
    04-13-2004
    Posts
    74

    Re: Activate file with date name

    Bump. I would like some input on this.

    Thanks, Cliff

  3. #3
    Forum Contributor
    Join Date
    06-17-2010
    Location
    Dallas, TX
    MS-Off Ver
    Excel 2010
    Posts
    157

    Re: Activate file with date name

    I don't think you need quotes around sPath since it's a variable.

    So the fifth from last line of code should look something like this:
    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    04-13-2004
    Posts
    74

    Re: Activate file with date name

    Quote Originally Posted by Ricker090 View Post
    I don't think you need quotes around sPath since it's a variable.

    So the fifth from last line of code should look something like this:
    Please Login or Register  to view this content.
    Hi,

    I removed the quotes but that didn't make a difference. The code get stuck on the next line from the line you mentioned. It stops at "Windows(WorkbookName).Activate" with an Out of range error. In the locals window i can see that 'WorkbookName is correct.

    Cliff

  5. #5
    Forum Contributor
    Join Date
    06-17-2010
    Location
    Dallas, TX
    MS-Off Ver
    Excel 2010
    Posts
    157

    Re: Activate file with date name

    Oh, I see. "Windows(WorkbookName).Activate" isn't supposed to work unless the workbook is open.

    Try this:

    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    04-13-2004
    Posts
    74

    Re: Activate file with date name

    Quote Originally Posted by Ricker090 View Post
    Oh, I see. "Windows(WorkbookName).Activate" isn't supposed to work unless the workbook is open.

    Try this:

    Please Login or Register  to view this content.
    The workbook is already open and the macro is intended to update the pivot in the workbook. That is why I just needed to activate the workbook. However; i went ahead and put your suggested 'Open Filename' in the code and it ran. (took out the activate.) Of course it gave me an error the workbook was already open but I answered Yes to reopen and the macro completed. So there is something wrong with my Activate code because it stops there and not with your Open code. Any thoughts?

    Thanks for helping on this. Cliff

  7. #7
    Forum Contributor
    Join Date
    06-17-2010
    Location
    Dallas, TX
    MS-Off Ver
    Excel 2010
    Posts
    157

    Re: Activate file with date name

    I didn't realize that you already had the workbook open.

    You don't need to define the path if it's already open. All you need is the name of the file.

    Try this:

    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    04-13-2004
    Posts
    74

    Re: Activate file with date name

    Quote Originally Posted by Ricker090 View Post
    I didn't realize that you already had the workbook open.

    You don't need to define the path if it's already open. All you need is the name of the file.

    Try this:

    Please Login or Register  to view this content.
    That was it! Many thanks for taking the time with me.
    Enjoy the coming holidays.
    Cliff

  9. #9
    Forum Expert ConneXionLost's Avatar
    Join Date
    03-11-2009
    Location
    Victoria, Canada
    MS-Off Ver
    2010
    Posts
    2,952

    Re: Activate file with date name

    Don't quote whole posts -- it's just clutter.

    If you are responding to a post out of sequence, limit quoted content to a few relevant lines that makes clear to whom and what you are responding.
    Would you like to say thanks? Please click the: " Add Reputation" button, on the grey bar below the post.

+ 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