i'm trying to read the autotex entries from a template and am getting this error:
Unable to cast COM object of type 'System.__ComObject' to interface type 'Microsoft.Office.Interop.Word.BuildingBlock'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{BFD3FC23-F763-4FF8-826E-1AFBF598A4E7}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
oTpl is initizialized and has a doc (count=1)
Code:
Public Sub LoadAutoText()
Dim app As Word.Application = New Word.Application()
Dim sPath = app.Options.DefaultFilePath(WdDefaultFilePath.wdUserTemplatesPath) & "\" & TPL
'create template
If Not FileIO.FileSystem.FileExists(sPath) Then
app.Documents.Add(Visible:=False)
app.Documents(1).SaveAs2(sPath, WdSaveFormat.wdFormatXMLTemplate)
End If
app.Documents.Open(sPath, [ReadOnly]:=True)
oTpl = app.ActiveDocument.AttachedTemplate
ReDim Preserve arrCustAT(5)
////// error occures here //////
arrCustAT(0) = oTpl.BuildingBlockTypes(wdTypeAutoText).Categories("Notariat").BuildingBlocks
///// end //////
arrCustAT(1) = oTpl.BuildingBlockTypes(wdTypeCustomAutoText).Categories("Grundbuch").BuildingBlocks
arrCustAT(2) = oTpl.BuildingBlockTypes(wdTypeCustomAutoText).Categories("Konkurs").BuildingBlocks
arrCustAT(3) = oTpl.BuildingBlockTypes(wdTypeCustomAutoText).Categories("Personelles").BuildingBlocks
arrCustAT(4) = oTpl.BuildingBlockTypes(wdTypeCustomAutoText).Categories("Rechnungswesen").BuildingBlocks
app.Quit()
End Sub
Unable to cast COM object of type 'System.__ComObject' to interface type 'Microsoft.Office.Interop.Word.BuildingBlock'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{BFD3FC23-F763-4FF8-826E-1AFBF598A4E7}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
oTpl is initizialized and has a doc (count=1)
Code:
Public Sub LoadAutoText()
Dim app As Word.Application = New Word.Application()
Dim sPath = app.Options.DefaultFilePath(WdDefaultFilePath.wdUserTemplatesPath) & "\" & TPL
'create template
If Not FileIO.FileSystem.FileExists(sPath) Then
app.Documents.Add(Visible:=False)
app.Documents(1).SaveAs2(sPath, WdSaveFormat.wdFormatXMLTemplate)
End If
app.Documents.Open(sPath, [ReadOnly]:=True)
oTpl = app.ActiveDocument.AttachedTemplate
ReDim Preserve arrCustAT(5)
////// error occures here //////
arrCustAT(0) = oTpl.BuildingBlockTypes(wdTypeAutoText).Categories("Notariat").BuildingBlocks
///// end //////
arrCustAT(1) = oTpl.BuildingBlockTypes(wdTypeCustomAutoText).Categories("Grundbuch").BuildingBlocks
arrCustAT(2) = oTpl.BuildingBlockTypes(wdTypeCustomAutoText).Categories("Konkurs").BuildingBlocks
arrCustAT(3) = oTpl.BuildingBlockTypes(wdTypeCustomAutoText).Categories("Personelles").BuildingBlocks
arrCustAT(4) = oTpl.BuildingBlockTypes(wdTypeCustomAutoText).Categories("Rechnungswesen").BuildingBlocks
app.Quit()
End Sub