INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Macro runs from editor but not from ribbon - MS Project

Macro runs from editor but not from ribbon - MS Project

(OP)
I have noticed some macro's run ok from the editor but when I put a button on the ribbon the macro looks like nothing happens.
So I then run one line at a time and notice the macro will run, but when it reaches "End Sub" everything undoes.
Not sure if this has been discussed on here but I would be interested in feedback on this.

I have tried "exit sub" before End Sub and moved the macro to a different module but no joy.

RE: Macro runs from editor but not from ribbon - MS Project

Hi,

Plz post your code.

Skip,

glassesJust traded in my OLD subtlety...
for a NUance!tongue

RE: Macro runs from editor but not from ribbon - MS Project

(OP)

CODE

Sub MyLink_Click()

 On Error Resume Next
Application.screeupdating = False
DisplayAlerts = False
Application.OutlineShowAllTasks

Dim Nw As String
Dim i, TTL, TTL2 As Integer
Dim t As Task


'Dim SS1 As String

If MsgBox("Message Here?", vbYesNo + vbQuestion, "Message Title") = vbNo Then Exit Sub
LOAD_WLOGO.Show

For Each t In ActiveProject.Tasks
 i = t.ID - 1
 

If t.Summary = NO Then

If Left(t.Name, InStr(InStr(1, t.Name, " ") + 1, t.Name, " ") - 1) = "" Then
    SS1 = Left(t.Name, InStr(1, t.Name, " "))
Else
    SS1 = Left(t.Name, InStr(InStr(1, t.Name, " ") + 1, t.Name, " ") - 1)
End If

If t.Text2 = ActiveProject.Tasks(i).Text2 And t.Text26 = "NEW" Then
    If t.Name Like "*Keyword*" Or t.Name Like "*Keyword2*" Or t.Name Like "*Keyword3*" _
        Or ActiveProject.Tasks(i).Name Like "*" & SS1 & "*" And ActiveProject.Tasks(i).Summary = NO And t.Duration > 0 Then
        LinkTasksEdit From:=t.ID - 1, To:=t.ID, Type:=3
    Else
        If t.Duration > 0 Then
         t.Predecessors = i
        End If
    End If
End If

End If
DoEvents
TTL = (((ActiveProject.Tasks.Count - t.ID) / ActiveProject.Tasks.Count) * 100) * 2
TTL2 = ((t.ID / ActiveProject.Tasks.Count) * 100) * 2
LOAD_WLOGO.Image1.Width = TTL
LOAD_WLOGO.Image1.Left = TTL2
LOAD_WLOGO.Caption = "Linking Tasks " & Round(TTL2 / 2, 0) & "%"
'----------------------------------------------------------------------------------------------------

Next t
Unload LOAD_WLOGO
DisplayAlerts = True
Application.ScreenUpdating = True

End Sub 

RE: Macro runs from editor but not from ribbon - MS Project

One quick thing to consider/test would be making sure that the VBA Project you think you're referencing is the one you actually are referencing. For instance, it could be you think you're referencing "MyCoolFancyProject", but you're actually referencing "Personal.XLS"

What makes me say this is this piece:

CODE

For Each t In ActiveProject.Tasks
i = t.ID - 1 

That's looking at the active project at the moment you click the button. If it's looking at a project that is outside the scope of what you're trying to accomplish, then it'll end in an error or just not do anything, depending on your code. I didn't look at the rest.

One big thing that'll help you get help here, by the way, is to put that code in CODE brackets using the TGML. There's a question mark just left of "Preview" when typing a post that'll give you all the details. You can type the [CODE]MyCode[/CODE] or you can use the code button that is a piece of paper with "<>" on it (in blue) - 3 icons to the left from the question mark (help button).

"But thanks be to God, which giveth us the victory through our Lord Jesus Christ." 1 Corinthians 15:57

RE: Macro runs from editor but not from ribbon - MS Project

(OP)
Thanks Kjv
I also use other macros with

CODE

For Each t In ActiveProject.Tasks
i = t.ID - 1 
And do not have the same issue. Also the script plays out then on "End sub" reverts back to nothing.
Ive seen this before on the odd occasion but never have been able to work it out.

RE: Macro runs from editor but not from ribbon - MS Project

CODE

Application.screeupdating = False 

Don't know what effect updating (or not) your scree will have. That's usually a slippery mess, sliding down the mountain side. Your procedure shouldn't even compile/run.

But try ...

CODE

Application.screenupdating = False 

Skip,

glassesJust traded in my OLD subtlety...
for a NUance!tongue

RE: Macro runs from editor but not from ribbon - MS Project

(OP)
No Change,
Just cant get my head around why it runs from the editor and not from the ribbon

RE: Macro runs from editor but not from ribbon - MS Project

First of all, comment On Error Resume Next and analyse and debug your code. This may require additional tests in code. I guess that LOAD_WLOGO is modeless userform.

You could fix inconsistencies (as Summary property is boolean, you should rather compare it to True/False instead of NO variable) and possible gaps (SS1 can be zero length string, next it is used in comparison statement with wildcard character).

Test conditions, names of objects involved and changed properties immediately (with MsgBox for instance).

Comment DisplayAlerts = False, some people refer this setting as a bug. Looks like it works, however MS declares DisplayAlerts as a property of Application object, so the proper statement should be Application.DisplayAlerts = False.

combo

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close