2011-09-15 4 views
3

Microsoft에서 프로젝트를 실행하기 위해 제공되는 기본 제공 MSF Agile 5.0 프로세스 템플릿을 사용하고 있습니다. 특히, 반복 백 로그 Excel 시트는 프로젝트 관리를 수행하는 데 매우 유용합니다.TFS 2010 작업 항목 쿼리에서 Excel을 자동으로 새로 고치는 방법

그러나 시트 번호 1의 반복 백 로그가 최신이 아닌 상황이 발생했습니다. Excel 통합 문서를 연 후 사용자는 으로 명시 적으로 팀 탭의 새로 고침 단추를 클릭하면 최신 데이터를 볼 수 있습니다.

질문 : Excel (2007)이 통합 문서를 열 때 Iteration Backlog를 새로 고치고 연결된 TFS 2010 workitem 쿼리와 동기화하도록하려면 어떻게해야합니까?

기록 된 매크로가 트리 계층 구조로 쿼리를 새로 고칠 수 없기 때문에 다른 사람이 새로 고침 단추를 클릭하여 매크로를 기록하도록 제안했습니다. (적어도 매크로를 실행하면 매크로가 나에게 그래서). ActiveWorkbook.RefreshAll

에만 연결해야합니다 : 기록 된 매크로 그냥

답변

4

일부 프라이머 손의 문제로 지금에
Types of lists
Converting a Input list to Query list

.
이전 답변자는 통합 문서 열기 이벤트에서 실행되는 코드가 필요하다고 말했기 때문입니다. 나는 그 부분을 이미 알고 있다고 믿는다.
refreshall 메서드는 일반 사항이며 데이터 연결, 수식 및 일반 쉐어 포인트 목록에서만 작동합니다.
리본 메뉴에서 팀 메뉴를 사용해야합니다.
다음 코드 조각은 작업 항목 데이터가 들어있는 테이블을 나타내는 목록 개체를 가져 오는 방법과 함께 방법을 보여줍니다.
Synchronize TFS and Excel via VBA

링크가 끊어지는 경우 코드의 부분 재생이 이어집니다 (팀 메뉴 만 활성화 됨). 이미 문서의 MSDN 링크는 깨진 보이는 (또는 아마를 ..)

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 
Sub RefreshTeamQuery(shtTFSExcel_Name As String) '(rangeName 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 
End Sub 
+0

이것은 정답입니다. 매력처럼 일하고! 고명 익명 유형. – kroonwijk

+0

기쁘게하기 위해 –

+1

코드의 일부가 RefreshTeamQuery 메서드에서 누락되었습니다. 나는 대답을 편집하려했지만 거부되었으므로 아래의 전체 코드로 새로운 대답을 만들었습니다. –

-1

내가 아는 한 :-) 버튼을 클릭하는 다른 작업을 수행, 모든 XLS 파일 데이터 소스를 새로 VB 기능이있다 최대 통합 문서 이벤트를 엽니 다. 목록 유형에 대한 MSDN 라이브러리에서

+0

난 그냥 그것을 시도했다. 하지만 TFS 작업 목록 항목을 새로 고치거나 업데이트하지는 않습니다. Excel과 TFS 간의 통합을 처리하는 특별한 것이 있다고 생각합니다. 그것은 단지 일반적인 데이터 연결이나 외부 데이터 소스가 아닙니다. – kroonwijk

+0

통합 문서 열기 이벤트는 첫 번째 부분을 해결하고 RefreshAll 메서드는 두 번째 요구 사항을 해결하지 못합니다. –

+0

제 경험상 RefreshAll은 Access 2003에서 절대로 작동하지 않았습니다. 항상 새로 고침을 반복하고 표준 새로 고침을 수행했습니다. – PowerUser

1

난 그냥 익명 형식의 답변을 편집하려하지만 내 편집은 새로운 대답을 그렇게 거부되었습니다. 그는 링크 된 기사 (here은 원본 코드에 대한 직접 링크입니다)에 표시된대로 RefreshTeamQuery 메서드의 코드 일부가 누락되었습니다.

워크 북 열기 이벤트에서이 단추를 호출하는 데 여전히 문제가 있습니다. 왜냐하면 해당 단추가 도구 모음에서 만들어 지거나 wookbook이 열렸을 때 워크 시트에 연결되어 있다고 생각하지 않기 때문입니다. 단추에 코드를 사용하면 잘 작동합니다.

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 
Sub RefreshTeamQuery(shtTFSExcel_Name As String) '(rangeName 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(shtTFSExcel_Name).ListObjects(1).Range 

    teamQueryRange.Worksheet.Select 
    teamQueryRange.Select 
    refreshControl.Execute 

    activeSheet.Select 

    Application.ScreenUpdating = True 
End Sub 
0

이 버전은 비슷하지만, 그것은 당신이 범위에 통과해야하지만, 단순히 TFS 테이블이 사용자에 의해 (선택)를 클릭 한 가정하지 않는 옵션이 있습니다.

원래 기능

도 있습니다 :

Sub RefreshTeamQuery() 
    Dim sel As Range: Set sel = Application.Selection: If sel Is Nothing Then Exit Sub 
    Dim lo As ListObject: Set lo = sel.ListObject: If lo Is Nothing Then Exit Sub 
    RefreshTeamQueryWithList lo 
End Sub 

Sub RefreshTeamQueryWithList(lo As ListObject) 

    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 

    On Error GoTo errorHandler 

    '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 = lo.Range 

    teamQueryRange.Worksheet.Select 
    teamQueryRange.Select 
    refreshControl.Execute 

    activeSheet.Select 
    Application.ScreenUpdating = True 

errorHandler: 
    If Not activeSheet Is Nothing Then activeSheet.Select 
    Application.ScreenUpdating = True 
End Sub 

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 
관련 문제