使用 Excel VBA,您可以发布已更改的查询吗?

问题描述 投票:0回答:1

Excel VBA ADO/TFS 添加支持使用 IDC_REFRESH 常量刷新工作表中的 ADO 查询。有关详细信息,请参阅(在 CommandBarButton 上执行操作未能更新工作项)。

我也希望能够使用 vba 宏发布查询,但一直无法弄清楚。

我进行了多次搜索,寻找有关调用“发布”按钮的功能的文档。

没有成功。我还尝试修改我的代码以使用 IDC_PUBLISH 查找“发布”按钮/控件以及上面 stackoverflow 链接中引用的相同代码。

有人知道这是否可能吗?

excel vba plugins tfs ado
1个回答
0
投票

好的,Kevin Lu-MSFT 给了我足够的见解来解决这个问题。谢谢凯文! 这是多年来一直流传的子例程的更新版本。该子例程将感兴趣的控件名称子字符串作为参数,然后执行该控件。

我已经测试过了,它有效!我希望它对其他人有帮助。

Call ExecuteTeamControlOnWorksheet("OneFeature", "IDC_REFRESH") ' Execute Refresh
Call ExecuteTeamControlOnWorksheet("OneFeature", "IDC_SYNC") ' Execute Publish

Private Sub ExecuteTeamControlOnWorksheet(worksheetName As String,teamControlName As String)

    Dim activeSheet As Worksheet
    Dim teamQueryRange As Range
    Dim refreshControl As CommandBarControl
    
    Set refreshControl = FindTeamControl(teamControlName)

    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(2).Range

    teamQueryRange.Worksheet.Select
    teamQueryRange.Select
        
    refreshControl.Execute
    

    activeSheet.Select
    

    Application.ScreenUpdating = True
    
    
    'MsgBox "Completed " + worksheetName + " Query "
    
    Debug.Print "Completed " + worksheetName + " Query "
        
End Sub

Private Function FindTeamControl(tagName As String) As CommandBarControl

    Dim commandBar As commandBar
    Dim teamCommandBar As commandBar
    Dim control As CommandBarControl
    
' Caption is the name displayed on the Control on the Excel Team Tab
' Tag is the Tag name for that control. This is the string this
' The original example of this dropped the -TBB off the end, 
' so I've been following this practice
' To find the Refresh button, use IDC_REFRESH, for Publish use IDC_SYNC
'   Caption               : Tag
'   New List              : IDC_NEW_WI_LIST-TBB
'   Get Work Items        : IDC_IMPORT-TBB
'   Publish               : IDC_SYNC-TBB
'   Refresh               : IDC_REFRESH-TBB
'   List                  : IDC_CONFIGURE_LIST-TBB
'   Choose Columns        : IDC_COLUMN_CHOOSER-TBB
'   Links and Attachments : IDC_LINKS_ATTACHMENTS-TBB
'   Open in Web Access    : IDC_OPEN_IN_WEB_ACCESS-TBB
'   Select User           : IDC_IDENTITY_PICKER-TBB
'   Add Tree Level        : IDC_ADD_SUBLEVEL_COLUMN-TBB
'   Add Child             : IDC_ADD_NEW_CHILD-TBB
'   Indent                : IDC_INDENT-TBB
'   Outdent               : IDC_OUTDENT-TBB

    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
© www.soinside.com 2019 - 2024. All rights reserved.