VBA Error when running Excel on Windows Terminal Server 2003

The following error appears when loading an Excel workbook with quite a bit of code behind it:
Invalid procedure call or argument (Error 5)

The error only appears when launching the file in a Citrix/Windows 2003 Terminal Services session.  Ordinarily, when the file is launched under Windows XP, the code runs without issue.

We are standardized on Excel XP SP3.

The offending line of code appears to be:
Application.CommandBars.Add(Name:=MacroToolbarName).Visible = True

Thanks for your help!!
Sub zMacroToolbarManager()
 
    Const MacroToolbarName As String = "JSA"
    
    Dim ToolbarItem As Object
    Dim ToolbarFound As Integer
    
    ' See if the toolbar exists
    On Error Resume Next
        Set ToolbarItem = CommandBars(MacroToolbarName).Controls(1)
        ToolbarFound = Err
    On Error GoTo 0
    
    ToolbarFound = (ToolbarFound = 0)
    
    If (ToolbarFound = False) Then
        Application.CommandBars.Add(Name:=MacroToolbarName).Visible = True
    Else
        For Each ToolbarItem In CommandBars(MacroToolbarName).Controls
            ToolbarItem.Delete
        Next ToolbarItem
    End If

Open in new window

swamitommiAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Wayne Taylor (webtubbs)Commented:
Try this instead.....
    Const MacroToolbarName As String = "JSA"
    Dim ToolbarObject As CommandBar
    On Error Resume Next
    Set ToolbarObject = Application.CommandBars(MacroToolbarName)
    If Err <> 0 Then
        Set ToolbarObject = Application.CommandBars.Add(Name:=MacroToolbarName)
        ToolbarObject.Visible = True
    Else
        For Each ToolbarItem In CommandBars(MacroToolbarName).Controls
            ToolbarItem.Delete
        Next ToolbarItem
    End If
    Err.Clear
    On Error GoTo 0

Open in new window

0
Cláudio RodriguesFounder and CEOCommented:
Another question is, does this happen when the user has administrator rights on the Citrix/TS session?

Cláudio Rodrigues

Microsoft MVP
Windows Server - Terminal Services
0
swamitommiAuthor Commented:
Yes.  It happens regardless of the user's rights on the server.
0
10 Tips to Protect Your Business from Ransomware

Did you know that ransomware is the most widespread, destructive malware in the world today? It accounts for 39% of all security breaches, with ransomware gangsters projected to make $11.5B in profits from online extortion by 2019.

swamitommiAuthor Commented:
Thanks for the code snippet, webtubbs!  Of course, now I have a new error: the good ol' "Can't find project or library".  Seems not to like CommandBar.  Funny thing is, when I run through the Object Browser, nothing is shown as missing.  The CommandBar class is, in fact, right there.  Hmmm...
0
swamitommiAuthor Commented:
Here's a new one, coming off the code snippet you gave me, webtubbs: "Compile error: For Each control variable must be Variant or Object".  This is coming off of ToolbarItem in the For Each.
0
swamitommiAuthor Commented:
Problem was Solver.  webtubbs got me part of the way there, though - so thanks!  Solver needed to be removed and re-installed on a per-user basis.  Go figure.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Server OS

From novice to tech pro — start learning today.