Cannot run the macro "macroname". The macro may not be available in this workbook or all macros may be disabled

Historik

New Member
Joined
Sep 15, 2014
Messages
10
Hi,

I have a problem with automating and refreshing my TFS (Team Foundation Server addin tool for Excel). The code itself is actually working and running a public sub is also refreshing my input live.

However, when I want to automate this with an ontime code, it's not working. Giving the error "Cannot run the macro "macroname". The macro may not be available in this workbook or all macros may be disabled".

eu32vb.png


I've pasted the following code in Sheet2 (Microsoft Objects)

Code:
Private Sub RefreshTeamQueryOnWorksheet(worksheetName As String)

    Dim activeSheet As Worksheet
    Dim teamQueryRange As Range
    Dim refreshControl As CommandBarControl


    Set refreshControl = FindTeamControl("IDC_REFRESH")


    If refreshControl Is Nothing Then
        MsgBox "Could not find Team Foundation commands in Ribbon. Please make sure that the Team Foundation     Excel plugin is installed.", vbCritical
        Exit Sub
    End If


    ' Disable screen updating temporarily so that the user doesn’t see us selecting a range
    Application.ScreenUpdating = False


    ' Capture the currently active sheet, we will need it later
    Set activeSheet = ActiveWorkbook.activeSheet
    Set teamQueryRange = Worksheets(worksheetName).ListObjects(1).Range


    teamQueryRange.Worksheet.Select
    teamQueryRange.Select
    refreshControl.Execute


    activeSheet.Select


    Application.ScreenUpdating = True
End Sub

Code:
Private Function FindTeamControl(tagName As String) As CommandBarControl


    Dim commandBar As commandBar
    Dim teamCommandBar As commandBar
    Dim control As CommandBarControl


    For Each commandBar In Application.CommandBars
        If commandBar.Name = "Team" Then
            Set teamCommandBar = commandBar
            Exit For
        End If
    Next


    If Not teamCommandBar Is Nothing Then
        For Each control In teamCommandBar.Controls
            If InStr(1, control.Tag, tagName) Then
                Set FindTeamControl = control
                Exit Function
            End If
        Next
    End If
End Function


Code:
Public Sub UpdateTFS()
RefreshTeamQueryOnWorksheet ("Sheet2")
End Sub

I've inserted a module with the following code run the UpdateTFS code per 10 minutes.

Code:
sub test()
Application.OnTime Now + TimeValue("00:10:00"), "UpdateTFS" 
end sub

Any suggestions?
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Try putting the name of the Sheet code module that contains the macro in front of it like this:

Code:
Application.OnTime Now + TimeValue("00:10:00"), "Sheet1.UpdateTFS"

The name is the one next to the icon and not the one in brackets (which is the display name of the sheet).

WBD
 
Upvote 0
Hi there,

At least as shown, you could also ditch UpdateTFS() by including the argument with OnTime. Please note the doubled-up quote marks as well as the single quotes included.
Code:
  Application.OnTime Now + TimeSerial(0, 10, 0), "'Sheet2.RefreshTeamQueryOnWorksheet ""Sheet2""'"
Hope that helps,

Mark
 
Upvote 0

Forum statistics

Threads
1,223,243
Messages
6,170,971
Members
452,371
Latest member
Frana

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top