Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Macro runs from editor but not from ribbon - MS Project

Status
Not open for further replies.

Palmcrest

Technical User
Jul 10, 2006
66
0
0
AU
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.
 
Hi,

Plz post your code.

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
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
 
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 [ignore]
Code:
MyCode
[/ignore] 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
 
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.
 
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.scree[b][highlight]n[/highlight][/b]updating = False

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
No Change,
Just cant get my head around why it runs from the editor and not from the ribbon
 
First of all, comment [tt]On Error Resume Next[/tt] 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 [tt]Summary[/tt] property is boolean, you should rather compare it to [tt]True/False[/tt] instead of [tt]NO[/tt] variable) and possible gaps ([tt]SS1[/tt] 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 [tt]MsgBox[/tt] for instance).

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

combo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top