Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

word get buidingblocktypes by category

Status
Not open for further replies.

envoleo

Programmer
Dec 1, 2010
2
CH
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
 
If Not FileIO.FileSystem.FileExists(sPath) Then
Sorry, but your code don't seem to be VBA ...

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top