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

Excel COM variant

jvandeven
New Contributor I
763 Views

Hello all,

I have been writing to Excel from Fortran for a while now using the $Workbook_SaveAs COM subroutine.  I would like to turn off a dialog box from Excel, which pops up each time I ask my program to save a given excel file to a location where an old version of the file already exists.  I think that I need to set the ConflictResolution variable to "xlLocalSessionChanges", but do not know how to do this. My code snippit is below:

CALL VariantInit(vBSTR3)
vBSTR3%VT = VT_BSTR
bstr3 = ConvertStringToBSTR(outputFileName)
vBSTR3%VU%PTR_VAL = bstr3
Call VariantInit(vConflict)
vConflict%VT = VT_BSTR
conflict = ConvertStringToBSTR("xlLocalSessionChanges")
vConflict%VU%PTR_VAL = conflict
call $Workbook_SaveAs(workbook, vBSTR3, ConflictResolution=vConflict)

Many thanks in advance for any advice you may have to give,

Justin.

0 Kudos
1 Solution
jvandeven
New Contributor I
763 Views
More digging suggested that the following code would implement the "conflict resolution" that I refer to above: Call VariantInit(vConflict) vConflict%VT = VT_I4 vConflict%VU%LONG_VAL = xlLocalSessionChanges CALL VariantInit(vBSTR3) vBSTR3%VT = VT_BSTR bstr3 = ConvertStringToBSTR(outFileName) vBSTR3%VU%PTR_VAL = bstr3 call $Workbook_SaveAs(workbook, vBSTR3, ConflictResolution=vConflict) My reason for wanting to implement this in the first place was to suppress pop-up warnings from Excel. It turns out, however, that the above does not achieve this. What is required is a call to the following subroutine: call $Application_SetDisplayAlerts(excelapp, .false., $STATUS = status) where excelapp is the pointer to the excel application (e.g. CALL COMCREATEOBJECT ("Excel.Application", excelapp, status) ) All the best, Justin.

View solution in original post

0 Kudos
1 Reply
jvandeven
New Contributor I
764 Views
More digging suggested that the following code would implement the "conflict resolution" that I refer to above: Call VariantInit(vConflict) vConflict%VT = VT_I4 vConflict%VU%LONG_VAL = xlLocalSessionChanges CALL VariantInit(vBSTR3) vBSTR3%VT = VT_BSTR bstr3 = ConvertStringToBSTR(outFileName) vBSTR3%VU%PTR_VAL = bstr3 call $Workbook_SaveAs(workbook, vBSTR3, ConflictResolution=vConflict) My reason for wanting to implement this in the first place was to suppress pop-up warnings from Excel. It turns out, however, that the above does not achieve this. What is required is a call to the following subroutine: call $Application_SetDisplayAlerts(excelapp, .false., $STATUS = status) where excelapp is the pointer to the excel application (e.g. CALL COMCREATEOBJECT ("Excel.Application", excelapp, status) ) All the best, Justin.
0 Kudos
Reply