first_page the funky knowledge base
personal notes from way, _way_ back and maybe today

Microsoft Word 2007 VBA: RefreshCustomQuickParts()

Public Sub RefreshCustomQuickParts() Dim objRow As Word.Row Dim objCell As Word.Cell Dim strEntryName As String, strCategoryName As String, objEntryRange As Word.Range Dim strMsg As String Dim objNode As Word.XMLNode Dim objContentType As WdBuildingBlockTypes Dim objWordRange As Word.Range Dim i As Integer

With Application
    'Check for an active Document:
    If .Documents.count = 0 Then
        strMsg = "Please open a Word Document."
        Call VBA.MsgBox(strMsg, vbInformation + vbOKOnly, .Name)
        Exit Sub
    End If
    
    'Verify the document with the data:
    If .ActiveDocument.Name <> "Custom Quick Parts.docx" Then
        strMsg = "Please open or activate Word Document ""Custom Quick Parts.docx."""
        Call VBA.MsgBox(strMsg, vbInformation + vbOKOnly, .Name)
        Exit Sub
    End If

    .System.Cursor = wdCursorWait

    strCategoryName = "Songhay Custom Quick Parts"
    
    For Each objRow In .ActiveDocument.Tables(1).Rows
        For Each objCell In objRow.Cells
            With objCell
                
                Set objNode = .Range.XMLNodes(1)
                
                If .ColumnIndex = 1 Then
                    strEntryName = objNode.Text
                ElseIf .ColumnIndex = 2 Then
                    Set objEntryRange = objNode.Range
                End If
            
            End With
        Next
        
        Call .NormalTemplate.BuildingBlockEntries.Add(strEntryName, wdTypeCustomQuickParts, strCategoryName, objEntryRange)

    Next

    .System.Cursor = wdCursorNormal

    Call VBA.MsgBox("Custom Quick Parts refreshed.", vbInformation + vbOKOnly, .Name)
End With

End Sub

Public Sub RefreshCustomQuickPartsClick(ByVal control As IRibbonControl) Call RefreshCustomQuickParts End Sub

mod date: 2008-09-02T04:10:11.000Z