PDA

View Full Version : How to use Excel COM in Fortran.NET


happy lin
03-09-2004, 02:41 PM
I just start to learn manipulating about COM in Fortran.
I'd like to activate Excel in my Fortran code through COM,
but the following codes seem not to work.
I have successed initiate the Excel object, but I am stupid to use the object method. Can anyone tell me how?

program COMExample
! this is the namespace the COM object resides in
USE Excel
implicit none
type(Excel%ApplicationClass), pointer :: objExcel
! instantiates the COM object
allocate(objExcel, source=Excel%ApplicationClass())
! make calls to the COM methods
objExcel%Visible = .True. ! this line is OK

Call objExcel%Workbooks%Add() ! this line is Wrong!
pause

deallocate(objExcel)
end program COMExample

tzeis
03-10-2004, 11:16 PM
I don't have specific knowledge of Excel, but the form that you probably want to use is something like this:


type(Workbook), pointer :: aWorkbook
...
aWorkbook => objExcel%Workbooks%Add()


In other words, the WorkBooks%Add() method returns some object, and you want to declare a thing of that type to assign the result of the Add method. I would assume that WorkBooks is a collection and WorkBook is a single item in that collection.