Solved

VBA Excel 2000 - Week number

Posted on 2011-03-17
8
433 Views
Last Modified: 2012-05-11
Dear Experts,

I have a short code part which works fine for days and months from todays date

Dim SaveFileDay As String
Dim SaveFileMonth As String
SaveFileDay = Day(Date)
SaveFileMonth = Month(Date)

I would like to do the same but for weeks so determining the current number of week from todays date, but I am not sure in the syntax as the below logic does not work

Dim SaveFileWeek As String
SaveFileWeek = Weeknum(Date)

Could you please advise how it should be?

thanks,
0
Comment
Question by:csehz
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
8 Comments
 
LVL 42

Expert Comment

by:dlmille
ID: 35155276
Try:

SaveFileWeek = application.WorksheetFunction.WeekNum(Date)


Dave
0
 
LVL 42

Expert Comment

by:dlmille
ID: 35155283
PS - if you use the HELP (F1) in the VBA Project area, you can look up:  WorksheetFunction Object Members and then drill down on that to see all the worksheet functions that are available to you.

Cheers,

Dave
0
 
LVL 1

Author Comment

by:csehz
ID: 35155337
Dave thanks, applying this row I got error message that

Object does not support this property or method

I assume it is because like on the attached picture, maybe in Excell 2000 the Weeknum is not available? In that case do you have maybe some alternative solution?
wsf.jpg
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 42

Expert Comment

by:dlmille
ID: 35155341
Try APPLICATION.Worksheetfunction ?
0
 
LVL 42

Accepted Solution

by:
dlmille earned 500 total points
ID: 35155350
Sorry...

This link should get you what you need, if you have to build the weeknum function, yourself:

http://www.cpearson.com/excel/WeekNumbers.aspx

dave
0
 
LVL 1

Author Closing Comment

by:csehz
ID: 35155380
Dave thanks, it is interesting that anyway as normal function in a cell that works for me, so finally applied this

SaveFileWeek = Evaluate("=WEEKNUM(TODAY())")

thanks just again,
0
 
LVL 42

Expert Comment

by:dlmille
ID: 35155411
Good one.  I've recently (today) had problems with Evaluate in a macro (run many,many times appears to create excel/display/memory errors).

One potential alternative to evaluate is the following:

 
Function myEvaluate(testStr As String, fromMacro As Boolean) As Boolean
'attempt to do a better job than Application.Evaluate to evaluate these operations, as the Excel 4.0 macro calls (lots of them) create memory errors

    myEvaluate = False
      
    'First, check to see if this is a worksheet function, or is running from a macro
    
    'fall thru with FALSE evaluation on comparisons that don't make sense - e.g., comparing a string with a numeric equality
    On Error Resume Next
    If fromMacro Then 'must be running from a macro so leveraging defined name OK
        ActiveWorkbook.Names.Add Name:="toEvaluate", RefersToR1C1:="=False"
    
        ActiveWorkbook.Names("toEvaluate").RefersTo = "=" & testStr
        
        myEvaluate = [toEvaluate]
        
        ActiveWorkbook.Names("toEvaluate").Delete
    Else 'must be running as a worksheet function, so should be "safer" to run as-is with evaluate, as can't make defined name at this level
        myEvaluate = Application.Evaluate(testStr)
    End If
    
    If Err.Number <> 0 Then
        myEvaluate = False
    End If
    Err.Clear
    On Error GoTo 0
    
End Function

Open in new window


Dave
0
 
LVL 1

Author Comment

by:csehz
ID: 35155441
Thanks the info, good to know..
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question