Results 1 to 4 of 4
  1. #1
    Star Lounger
    Join Date
    Feb 2004
    Location
    Houston, Texas, USA
    Posts
    95
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Select Case with dropdown list (Project VBA)

    I've written a macro that uses Select Case to identify a macro from a dropdown list in a field in MS Project. I tried it using the Case plus the text from the different options in the dropdown list, but learned that Select Case doesn't work with strings. There is a row number associated with each option in the dropdown list. Can I use that row number with Case, and if so, how? I'm currently getting an "argument not valid" error at the GanttBarFormat line.

    For Each T In ActiveProject.Tasks
    var = T.ID
    var1 = T.Text22
    If T.Milestone Then
    Select Case var1
    Case "Engagement Meeting"
    var2 = "Eng Mtg"
    Case "SOW/Release Definition"
    var2 = "SOW/RDef"

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Select Case with dropdown list (Project VBA)

    I don't understand what kind of drop-down you have (I don't use Project), but Select Case does work with strings. However, it's usually case sensitive, so that can cause problems. If you MsgBox var1 immediately prior to the Select Case structure, are you getting the strings you expect?

    Do you explicitly declare var1 as a string or is it initializing as a variant? Not sure this would break the Select Case feature, but who knows?

  3. #3
    Star Lounger
    Join Date
    Feb 2004
    Location
    Houston, Texas, USA
    Posts
    95
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Select Case with dropdown list (Project VBA)

    I found out from some more reading that Select Case does work with strings but thanks for telling me that. I evidently had gotten hold of some bad information from another forum.

    I added the MsgBox to both var1 and var2 and they both work properly, showing the desired data. Code is as follows:

    Case "Go Live"
    var2 = "GL"
    MsgBox "Text22: " & var1
    MsgBox "Abbreviation: " & var2
    GanttBarFormat TaskID:=var, GanttStyle:=10, StartShape:=3, StartType:=1, _
    StartColor:=0, MiddleShape:=0, MiddlePattern:=1, MiddleColor:=0, _
    EndShape:=0, EndType:=0, EndColor:=0, BottomText:=var2

    I am more certain now that my problem is in the "BottomText:=var2" on GanttBarFormat but I don't know how to fix it.

    Can anyone help?

    Thanks,
    Caroline

  4. #4
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Select Case with dropdown list (Project VBA)

    <P ID="edit" class=small>(Edited by jscher2000 on 18-Mar-04 13:41. )</P>What does the online help say for GanttBarFormat: does it specify a variable type for this argument, or can you assign this argument using some other method? I can't seem to find the help file up at Microsoft.com.

    Since there is a parallel thread running on the Project forum, please continue over there. See <!rule=14>Rule 14<!/rule>.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •