+ Reply to Thread
Results 1 to 2 of 2

Need Help w/ Code

  1. #1
    Ronbo
    Guest

    Need Help w/ Code

    I have a routine that uses the name of the workbook to create a new workbook
    for the current month. It has worked perfectly through the year til now.
    Maybe it has something to do with the change of the year?

    Old workbook name = JOHN REPORT Nov 04 - WB w/macro to create new WB
    New workbook name should be = JOHN REPORT Dec 04
    Actual name the routine creates now is = JOHN REPORT 04 - with no month.

    The code is:

    tmpName = Left(ActiveWorkbook.Name, Len(ActiveWorkbook.Name) - 10)

    Select Case Month(Now()) - 1
    Case 1
    tmpMonth = "Jan "
    Case 2
    tmpMonth = "Feb "
    Case 3
    tmpMonth = "Mar "
    Case 4
    tmpMonth = "Apr "
    Case 5
    tmpMonth = "May "
    Case 6
    tmpMonth = "Jun "
    Case 7
    tmpMonth = "Jul "
    Case 8
    tmpMonth = "Aug "
    Case 9
    tmpMonth = "Sep "
    Case 10
    tmpMonth = "Oct "
    Case 11
    tmpMonth = "Nov "
    Case 12
    tmpMonth = "Dec "


    End Select

    tmpYear = Right(Year(Now()) - 1, 2)

    ActiveWorkbook.SaveAs Filename:="C:\Documents and
    Settings\Name\MyDocuments\PRC JOHN\" _
    & tmpName & tmpMonth & tmpYear, _
    FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
    ReadOnlyRecommended:=False, CreateBackup:=False

    Any help would truly be appreciated.

    Thanks




  2. #2
    Dana DeLouis
    Guest

    Re: Need Help w/ Code

    Hello. January is month 1. So, when you subtract 1, you are getting 0
    (zero). Your Select Case is not accounting for 0, so tmpMonth remains
    blank.
    See if any ideas here can help...

    Sub Demo()
    Dim dte As Date
    Dim str As String

    dte = Now
    dte = DateSerial(Year(dte), Month(dte) - 1, 1)

    'Your string here...
    str = Format(dte, "mmm yy")
    End Sub


    --
    Dana DeLouis
    Win XP & Office 2003


    "Ronbo" <[email protected]> wrote in message
    news:[email protected]...
    >I have a routine that uses the name of the workbook to create a new
    >workbook
    > for the current month. It has worked perfectly through the year til now.
    > Maybe it has something to do with the change of the year?
    >
    > Old workbook name = JOHN REPORT Nov 04 - WB w/macro to create new WB
    > New workbook name should be = JOHN REPORT Dec 04
    > Actual name the routine creates now is = JOHN REPORT 04 - with no month.
    >
    > The code is:
    >
    > tmpName = Left(ActiveWorkbook.Name, Len(ActiveWorkbook.Name) - 10)
    >
    > Select Case Month(Now()) - 1
    > Case 1
    > tmpMonth = "Jan "
    > Case 2
    > tmpMonth = "Feb "
    > Case 3
    > tmpMonth = "Mar "
    > Case 4
    > tmpMonth = "Apr "
    > Case 5
    > tmpMonth = "May "
    > Case 6
    > tmpMonth = "Jun "
    > Case 7
    > tmpMonth = "Jul "
    > Case 8
    > tmpMonth = "Aug "
    > Case 9
    > tmpMonth = "Sep "
    > Case 10
    > tmpMonth = "Oct "
    > Case 11
    > tmpMonth = "Nov "
    > Case 12
    > tmpMonth = "Dec "
    >
    >
    > End Select
    >
    > tmpYear = Right(Year(Now()) - 1, 2)
    >
    > ActiveWorkbook.SaveAs Filename:="C:\Documents and
    > Settings\Name\MyDocuments\PRC JOHN\" _
    > & tmpName & tmpMonth & tmpYear, _
    > FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
    > ReadOnlyRecommended:=False, CreateBackup:=False
    >
    > Any help would truly be appreciated.
    >
    > 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