+ Reply to Thread
Results 1 to 2 of 2

Week Number and current Hour

Hybrid View

  1. #1
    Valued Forum Contributor Macdave_19's Avatar
    Join Date
    03-14-2007
    Location
    Birmingham, England
    MS-Off Ver
    12.0
    Posts
    808

    Week Number and current Hour

    Hi folks,

    im a little stuck as ever!!!

    the following code:

    Sub GetDiscoData()
    Dim SSheet As String
    SSheet = InputBox("What Would you like to call the sheet?", "Name Sheet:") 'WeekNumber and Hour Here?
        Range("B5").Value = SSheet
    
        ActiveWorkbook.Worksheets.Add
        
        With ActiveSheet.QueryTables.Add(Connection:=Array( _
            "OLEDB;Provider=Microsoft.Jet.OLEDB.4.0;Password="""";User ID=Admin;Data Source=N:\BILLING\Business Billing\DISCO\Work\New\Discos.mdb;Mod" _
            , _
            "e=Read;Extended Properties="""";Jet OLEDB:System database="""";Jet OLEDB:Registry Path="""";Jet OLEDB:Database Password="""";Jet OLEDB:E" _
            , _
            "ngine Type=5;Jet OLEDB:Database Locking Mode=1;Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Global Bulk Transactions=1;Jet OLED" _
            , _
            "B:New Database Password="""";Jet OLEDB:Create System Database=False;Jet OLEDB:Encrypt Database=False;Jet OLEDB:Don't Copy Locale o" _
            , _
            "n Compact=False;Jet OLEDB:Compact Without Replica Repair=False;Jet OLEDB:SFP=False" _
            ), Destination:=Range("A1"))
            .CommandType = xlCmdTable
            .CommandText = Array("Base")
            .Name = "Discos"
            .FieldNames = True
            .RowNumbers = False
            .FillAdjacentFormulas = False
            .PreserveFormatting = True
            .RefreshOnFileOpen = False
            .BackgroundQuery = True
            .RefreshStyle = xlInsertDeleteCells
            .SavePassword = False
            .SaveData = True
            .AdjustColumnWidth = True
            .RefreshPeriod = 0
            .PreserveColumnInfo = True
            .SourceDataFile = "N:\BILLING\Business Billing\DISCO\Work\New\Discos.mdb"
            .Refresh BackgroundQuery:=False
        End With
    Dim Sname As String
    Dim Snew As String
    
    Snew = Sheets("Home").Range("B5").Value
    ActiveSheet.Name = Snew
    End Sub
    Basically it gets data from a database, sticks it in excel an renames the sheet, but i want to name the sheet as Follows:

    Wk50Hr12

    So basically the current Week number (50 at present) and the Current Hour (12 at the moment) but i don't know how i can achieve this.

    please help folks!!!

    thanks for reading
    Last edited by VBA Noob; 12-10-2007 at 09:02 AM.
    Mr MaGoo
    Magoo.Inc MMVII

    If i've helped please add to my Rep by Clicking on the Blue Scales in the top right hand corner of the post

  2. #2
    Registered User
    Join Date
    10-25-2006
    Posts
    54
    Hi

    Is the problem renaming the sheet ro getting the hour returned?

    activesheet.name="wk50hr12" will rename the tab OR
    sheets(x).name="wk50hr12" where x is the sheet number

    To get the hour you can use the hour function eg

    this_hour=hour(now)

    this will return an hour integer which you can use in the string for the name.

    A

+ 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