Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

VBA Excel 2000 - Week number

Posted on 2011-03-17
8
Medium Priority
?
436 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 42

Expert Comment

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

Accepted Solution

by:
dlmille earned 2000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
After seeing numerous questions for Dynamic Data Validation I notice that most have used Visual Basic to solve the problem. This suggestion is purely formula based and can be used in multiple rows.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.

650 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