+ Reply to Thread
Page 1 of 2 12 LastLast
Results 1 to 15 of 19

Thread: Constanty changing Workbook name( -2 business days)

  1. #1
    Forum Contributor
    Join Date
    08-31-2010
    Location
    US
    MS-Off Ver
    Excel 2003
    Posts
    198

    Constanty changing Workbook name( -2 business days)

    Hi all, is there a logic to tell excel that my workbook name is always changing.

    I need somehow to put logic so when my macros run and when it refers to code it knows that it is "file MM DD YYYY" (today (minus) 2 business days)

    Windows("file MM DD YYYY").Activate

    Any advice is very much appreciated..

    Thanks so much!
    Last edited by donyc; 02-13-2012 at 12:03 PM.

  2. #2
    Valued Forum Contributor mohd9876's Avatar
    Join Date
    05-04-2011
    Location
    Amman, Jordan
    MS-Off Ver
    Excel 2010
    Posts
    409

    Re: Constanty changing Workbook name( -2 business days)

    try this
    Workbooks("file " & Format(WorksheetFunction.WorkDay(Date, -2), "MM DD YYYY")).Activate

  3. #3
    Forum Contributor
    Join Date
    08-31-2010
    Location
    US
    MS-Off Ver
    Excel 2003
    Posts
    198

    Re: Constanty changing Workbook name( -2 business days)

    tried this..but getting run time error 438 'Object doesnt support this property or method'

    Workbooks("file " & Format(WorksheetFunction.WorkDay(Date, -2), "MM DD YYYY")).Activate

  4. #4
    Valued Forum Contributor mohd9876's Avatar
    Join Date
    05-04-2011
    Location
    Amman, Jordan
    MS-Off Ver
    Excel 2010
    Posts
    409

    Re: Constanty changing Workbook name( -2 business days)

    try adding the extension of the files, but even though that shouldn't give you the mentioned error!!

    Workbooks("file " & Format(WorksheetFunction.WorkDay(Date, -2), "MM DD YYYY") & ".xlsx").Activate

  5. #5
    Forum Contributor
    Join Date
    08-31-2010
    Location
    US
    MS-Off Ver
    Excel 2003
    Posts
    198

    Re: Constanty changing Workbook name( -2 business days)

    yeah I tried that.. got same thing.. really puzzled now lol..

  6. #6
    Valued Forum Contributor mohd9876's Avatar
    Join Date
    05-04-2011
    Location
    Amman, Jordan
    MS-Off Ver
    Excel 2010
    Posts
    409

    Re: Constanty changing Workbook name( -2 business days)

    could you do a little test just to know what is causing the error and tell me what happens:
    Dim sWBName as String
    sWBName = "file " & Format(WorksheetFunction.WorkDay(Date, -2), "MM DD YYYY") & ".xlsx"
    MsgBox sWBName
    Workbooks(sWBName).Activate

  7. #7
    Forum Contributor
    Join Date
    08-31-2010
    Location
    US
    MS-Off Ver
    Excel 2003
    Posts
    198

    Re: Constanty changing Workbook name( -2 business days)

    same, breaks w same error on Workbooks("file " & Format(WorksheetFunction.WorkDay(Date, -2), "MM DD YYYY") & ".xlsx").Activate

    I used excel 2003, but I did switch .xlsx to .xls but still neither works

  8. #8
    Valued Forum Contributor mohd9876's Avatar
    Join Date
    05-04-2011
    Location
    Amman, Jordan
    MS-Off Ver
    Excel 2010
    Posts
    409

    Re: Constanty changing Workbook name( -2 business days)

    mmmm, I guess then the problem maybe in the workday function maybe it is not available in 2003...
    try installing the analysis toolpack and try again
    http://office.microsoft.com/en-us/ex...005209339.aspx

  9. #9
    Forum Contributor
    Join Date
    08-31-2010
    Location
    US
    MS-Off Ver
    Excel 2003
    Posts
    198

    Re: Constanty changing Workbook name( -2 business days)

    its weird because the one in blue below right before it works for another file...

    Sub Clear()


    Dim PositionFileName As String
    Dim PositionFileName2 As String

    PositionFileName = "example" & Application.WorksheetFunction.Text((Date), "ddmmmm")
    PositionFileName2 = PositionFileName & ".XLS"
    Dim LastRow As Long
    LastRow = Cells.Find("*", [A1], , , xlByRows, xlPrevious).Row

    'Clear stuff
    Workbooks("file " & Format(WorksheetFunction.WorkDay(Date, -2), "MM DD YYYY") & ".xls").Activate Sheets("data").Select

  10. #10
    Valued Forum Contributor mohd9876's Avatar
    Join Date
    05-04-2011
    Location
    Amman, Jordan
    MS-Off Ver
    Excel 2010
    Posts
    409

    Re: Constanty changing Workbook name( -2 business days)

    did you try installing the analysis toolpack?
    the problem is probably in the Workday function
    did you see the link I sent you in the previous post?

  11. #11
    Forum Contributor
    Join Date
    08-31-2010
    Location
    US
    MS-Off Ver
    Excel 2003
    Posts
    198

    Re: Constanty changing Workbook name( -2 business days)

    yea looks like I already have it......

  12. #12
    Valued Forum Contributor mohd9876's Avatar
    Join Date
    05-04-2011
    Location
    Amman, Jordan
    MS-Off Ver
    Excel 2010
    Posts
    409

    Re: Constanty changing Workbook name( -2 business days)

    Wait..... is that the code you are using??????
    Workbooks("file " & Format(WorksheetFunction.WorkDay(Date, -2), "MM DD YYYY") & ".xls").Activate Sheets("data").Select
    if so... that is definitively the problem.... use this instead
    Workbooks("file " & Format(WorksheetFunction.WorkDay(Date, -2), "MM DD YYYY") & ".xls").Activate 
    Sheets("data").Select

  13. #13
    Forum Contributor
    Join Date
    08-31-2010
    Location
    US
    MS-Off Ver
    Excel 2003
    Posts
    198

    Re: Constanty changing Workbook name( -2 business days)

    that just got added on by mistake..using the one as you mentioned.. thanks for your help mate.. sorry for taking your time..not sure what else I can do to fix this.

  14. #14
    Valued Forum Contributor OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,647

    Re: Constanty changing Workbook name( -2 business days)

    WorkDay is not a valid method of WorksheetFunction pre 2007, precisely because it is part of the ATP.

    Does your code open the workbook in question, or does it just happen to be open already?
    Good luck.

  15. #15
    Forum Contributor
    Join Date
    08-31-2010
    Location
    US
    MS-Off Ver
    Excel 2003
    Posts
    198

    Re: Constanty changing Workbook name( -2 business days)

    workbook is already open but then I open different workbook and need to switch back to the original

+ 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.2.0