Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

COM Workbook_Close subroutine

jvandeven
New Contributor I
909 Views
I am unsure about how to use some of the features in the Workbook_Close subroutine of the COM interface that is generated by the Fortran Module Wizard. Specifically, the subroutine is defined as:
SUBROUTINE $Workbook_Close($OBJECT, SaveChanges, Filename, RouteWorkbook, $STATUS)
I would like to set the SaveChages variable to false. I think that this will avoid an Excel prompt that asks whether I would like to save changes to an excel file each time I access it from Fortran.

The SaveChanges variable is defined as:
TYPE (VARIANT), INTENT(IN), OPTIONAL :: SaveChanges
I realise that I should add code into my mainprogram that sets up a pointer, but am unsure what this code should be. The AutoDice example indicates that the following code should be used in relation to a string variant:
vBSTR1%VT = VT_BSTR
bstr1 = ConvertStringToBSTR("A2")
vBSTR1%VU%PTR_VAL = bstr1
Unfortunately, I suspect that the SaveChanges variable should be defined as a logical, and I have been unable to find an example of how to code this up.
Many thanks in advance for any help.
0 Kudos
1 Solution
IanH
Honored Contributor III
909 Views
Correct me if I'm wrong, but I think the VARIANT_BOOL_xxx constant should be assigned to the component that represents the variant's value, with the type being set to VT_BOOL, i.e.

SaveChanges%VT = VT_BOOL
SaveChanges%VU%BOOL_VAL = VARIANT_BOOL_FALSE



View solution in original post

0 Kudos
5 Replies
Steven_L_Intel1
Employee
909 Views
If you look at the definition of type VARIANT in IFWINTY you'll see this:

[fortran]          TYPE VARIANT
            SEQUENCE
                INTEGER*2       VT
                INTEGER*2       RESERVED1
                INTEGER*2       RESERVED2
                INTEGER*2       RESERVED3
                RECORD /VARIANT_UNION/ VU
          END TYPE VARIANT
          INTEGER*2, PARAMETER :: VARIANT_BOOL_TRUE = -1
          INTEGER*2, PARAMETER :: VARIANT_BOOL_FALSE = 0
          TYPE (VARIANT) :: OPTIONAL_VARIANT[/fortran]
This tells me that you want something like this:

SaveChanges%VT = VARIANT_BOOL_FALSE

I have not tested this.
0 Kudos
jvandeven
New Contributor I
909 Views
Worked perfectly - thanks, once again, Steve.
0 Kudos
IanH
Honored Contributor III
910 Views
Correct me if I'm wrong, but I think the VARIANT_BOOL_xxx constant should be assigned to the component that represents the variant's value, with the type being set to VT_BOOL, i.e.

SaveChanges%VT = VT_BOOL
SaveChanges%VU%BOOL_VAL = VARIANT_BOOL_FALSE



0 Kudos
jvandeven
New Contributor I
909 Views
Ha - I was just about to update this, as the code compiled, but didn't work. You are right - a shame I didn't read your message sooner, as I have just spent 30 minutes sorting this out.
0 Kudos
andrew_4619
Honored Contributor III
909 Views

[fortran]

SUBROUTINE CloseExelwithoutSaving(status) 
    IMPLICIT NONE
    INTEGER(4),intent(out)               :: status
    type(VARIANT)                        :: SaveChanges
    status=-1
    if(workbook.eq.0) return
    SaveChanges%VT = VT_BOOL
    SaveChanges%VU%BOOL_VAL = VARIANT_BOOL_FALSE
    !call $Workbook_Close(workbook, SaveChanges, Filename, RouteWorkbook, $STATUS)
    call $Workbook_Close(workbook, SaveChanges=SaveChanges, $STATUS=status)
    if(status.ne.0) return
    call Workbooks_Close(workbooks, status)
END SUBROUTINE CloseExelwithoutSaving

[/fortran]

Anyone solve this problem?  With the code above (the undeclared stuff is from the module variables BTW) the $Workbook_Close closes the worksheet leaving and empty excel window. Adding the Workbooks_Close closes the excel session but *only* when I exit the application that created it!

aNY

0 Kudos
Reply