G
Guest
I am trying to use code to verify that an excel spreadsheet was created from
a particular template. The template has a Custom Property called
"IsProcessFlow".
The code I am trying to use is this
'----------------------------------------------------------------------------------------
Dim result As DialogResult
Dim openFile As New OpenFileDialog()
Dim excelFileProperties As Microsoft.Office.Core.DocumentProperties
Dim excelFileProperty As DocumentProperty
'get an excel file
openFile.Filter = "xls files (*.xls)|*.xls"
result = openFile.ShowDialog()
'excelFile = openFile.FileName
excelApplication = New Microsoft.Office.Interop.Excel.Application
excelWorkbooks = excelApplication.Workbooks
excelWorkbook = excelWorkbooks.Open(openFile.FileName)
excelFileProperties = DirectCast(excelWorkbook.CustomDocumentProperties,
Microsoft.Office.Core.DocumentProperties)
'check to see if is correct Excel Template, if not exit
Dim correctExcelTemplate As Boolean = False
For Each excelFileProperty In excelFileProperties
If excelFileProperty.Name = "IsPLCProcessFlow" Then
correctExcelTemplate = True
End If
Next excelFileProperty
'------------------------------------------------------------
The DirectCast statement produces the following error:
"Unable to cast COM object of type 'System.__ComObject' to interface type
'Microsoft.Office.Core.DocumentProperties'. This operation failed because the
QueryInterface call on the COM component for the interface with IID
'{2DF8D04D-5BFA-101B-BDE5-00AA0044DE52}' failed due to the following error:
No such interface supported (Exception from HRESULT: 0x80004002
(E_NOINTERFACE))."
Am I missing something? All of the examples that I have seen use either the
CType() or DirectCast() methods to convert from the Excel objeect
CustomDocumentProperties to the Microsoft.Office.Core.DocumentProperties
interface.
a particular template. The template has a Custom Property called
"IsProcessFlow".
The code I am trying to use is this
'----------------------------------------------------------------------------------------
Dim result As DialogResult
Dim openFile As New OpenFileDialog()
Dim excelFileProperties As Microsoft.Office.Core.DocumentProperties
Dim excelFileProperty As DocumentProperty
'get an excel file
openFile.Filter = "xls files (*.xls)|*.xls"
result = openFile.ShowDialog()
'excelFile = openFile.FileName
excelApplication = New Microsoft.Office.Interop.Excel.Application
excelWorkbooks = excelApplication.Workbooks
excelWorkbook = excelWorkbooks.Open(openFile.FileName)
excelFileProperties = DirectCast(excelWorkbook.CustomDocumentProperties,
Microsoft.Office.Core.DocumentProperties)
'check to see if is correct Excel Template, if not exit
Dim correctExcelTemplate As Boolean = False
For Each excelFileProperty In excelFileProperties
If excelFileProperty.Name = "IsPLCProcessFlow" Then
correctExcelTemplate = True
End If
Next excelFileProperty
'------------------------------------------------------------
The DirectCast statement produces the following error:
"Unable to cast COM object of type 'System.__ComObject' to interface type
'Microsoft.Office.Core.DocumentProperties'. This operation failed because the
QueryInterface call on the COM component for the interface with IID
'{2DF8D04D-5BFA-101B-BDE5-00AA0044DE52}' failed due to the following error:
No such interface supported (Exception from HRESULT: 0x80004002
(E_NOINTERFACE))."
Am I missing something? All of the examples that I have seen use either the
CType() or DirectCast() methods to convert from the Excel objeect
CustomDocumentProperties to the Microsoft.Office.Core.DocumentProperties
interface.