<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: F90 to Excel: Function Worksheet_Add in Intel® Fortran Compiler</title>
    <link>https://community.intel.com/t5/Intel-Fortran-Compiler/F90-to-Excel-Function-Worksheet-Add/m-p/1648246#M174534</link>
    <description>&lt;P&gt;mfinnis is correct.&amp;nbsp; I put your files in the latest ifort. A couple of initial issues,&amp;nbsp;&amp;nbsp;ComReleaseObject is a function and you call as a subroutine, and I removed&amp;nbsp;!DEC$ ATTRIBUTES REFERENCE :: Filename in&amp;nbsp;Workbooks_Open to compile and link,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I added:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="fortran"&gt;    function fCVT_ptrToVariant (n)
        integer(handle), intent(IN)::    n
        type(VARIANT)::                fCVT_ptrToVariant
        fCVT_ptrToVariant%VT = VT_DISPATCH
        fCVT_ptrToVariant%VU%PTR_VAL = n
    end function fCVT_ptrToVariant&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="fortran"&gt;    ! Now add new sheet using AFTER argument: get the index number 
    ! of the active sheet, convert to VT before passing
    !idx = $Worksheet_GetIndex (hSheet)
    !VTidx = fCVT_Int4ToVariant (idx)
    VTidx = fCVT_ptrToVariant (hSheet)
    hSheet = Worksheets_Add(hWksheets,AFTER=VTidx,$STATUS=stat)
    count = Worksheets_GetCount(hWksheets)&lt;/LI-CODE&gt;&lt;P&gt;The code above then seems to work. You have some problems later in your example the sheet by name makes no sense as worksheet_add needs a sheet object not a name or index but I went no further.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 09 Dec 2024 15:27:05 GMT</pubDate>
    <dc:creator>andrew_4619</dc:creator>
    <dc:date>2024-12-09T15:27:05Z</dc:date>
    <item>
      <title>F90 to Excel: Function Worksheet_Add</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/F90-to-Excel-Function-Worksheet-Add/m-p/1647941#M174520</link>
      <description>&lt;P&gt;The goal is to open several new sheets on the Excel workbook and paste data calculated in Fortran.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want the sheets to appear in the workbook in the order they are created, so that Sheet1 will be the leftmost, sheet2 the next one to the right, etc.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Default behavior in VBA of the Worksheets.add method is&amp;nbsp; that a new sheet is added before the active sheet. Using the he optional After argument one can pass a variant to the sheet by &amp;nbsp;the referencing &amp;nbsp;the sheet after which you want put the new sheet.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The Worksheets_Add function in modExcel9A corresponds to the VBA method&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Function&amp;nbsp;Worksheets_Add ($OBJECT, Before, After, Count, Type, $STATUS)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;where $Object is the handle to the active sheet and Before, After, Count, Type are VARIANTs.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The function is working perfectly when used without optional arguments.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I set AFTER=varIdx or AFTER=varName the funtion returns an error.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have tried to eliminate all the obvious causes, such as that the Workbook, Application etc have not been initialized correctly.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have also pulled the name of the sheet and the index number of the sheet using $Worksheet_GetName and $WorkSheet_GetIndex to make sure I'm using valid reference. I have ruled out that my conversion from F90 string to VARIANT string is faulty as I use the same conversion in other portions of the code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does anyone have experience with this specific call to the VBA functions? Greatly appreciate any help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm still using the old CVF 6.6 compiler as I havent had time to port it to Intel, but I have checked that tha interfaces on the modExcel16 are basically the same as the ones I use.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Attached an example of the code, including&amp;nbsp; the source code for excel interfaces.&lt;/P&gt;</description>
      <pubDate>Sat, 07 Dec 2024 21:08:35 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/F90-to-Excel-Function-Worksheet-Add/m-p/1647941#M174520</guid>
      <dc:creator>mcadorno</dc:creator>
      <dc:date>2024-12-07T21:08:35Z</dc:date>
    </item>
    <item>
      <title>Re: F90 to Excel: Function Worksheet_Add</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/F90-to-Excel-Function-Worksheet-Add/m-p/1647988#M174525</link>
      <description>&lt;P&gt;I had a brief look at this, I don't seem to use $&lt;SPAN&gt;Worksheets_Add&amp;nbsp;though I do some things with worksheet index and name. I would need to make an example in the latest compiler etc. I&amp;nbsp; do not use CVF and my windows and excel is 64 bit....... But I expect this is a usage problem, exel/com can be quite fussy and sometime hard to figure. You made me laugh by the way "I'm still using the old CVF 6.6 compiler as I haven't had time to port it to Intel",&amp;nbsp; No time in&amp;nbsp; 20 years!!&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;For what it is worth a solution I have made use of is pre-creating an excel template with sheets, formats, graphs etc and then just populating tables in it from Fortran. If that is an option it saves a great deal of coding time.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 08 Dec 2024 11:25:13 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/F90-to-Excel-Function-Worksheet-Add/m-p/1647988#M174525</guid>
      <dc:creator>andrew_4619</dc:creator>
      <dc:date>2024-12-08T11:25:13Z</dc:date>
    </item>
    <item>
      <title>Re: F90 to Excel: Function Worksheet_Add</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/F90-to-Excel-Function-Worksheet-Add/m-p/1648017#M174530</link>
      <description>&lt;P&gt;The after and before variables are variants of type VT_DISPATCH with %vu%ptr_val set to a worksheet object.&lt;/P&gt;</description>
      <pubDate>Sun, 08 Dec 2024 18:03:40 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/F90-to-Excel-Function-Worksheet-Add/m-p/1648017#M174530</guid>
      <dc:creator>mfinnis</dc:creator>
      <dc:date>2024-12-08T18:03:40Z</dc:date>
    </item>
    <item>
      <title>Re: F90 to Excel: Function Worksheet_Add</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/F90-to-Excel-Function-Worksheet-Add/m-p/1648246#M174534</link>
      <description>&lt;P&gt;mfinnis is correct.&amp;nbsp; I put your files in the latest ifort. A couple of initial issues,&amp;nbsp;&amp;nbsp;ComReleaseObject is a function and you call as a subroutine, and I removed&amp;nbsp;!DEC$ ATTRIBUTES REFERENCE :: Filename in&amp;nbsp;Workbooks_Open to compile and link,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I added:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="fortran"&gt;    function fCVT_ptrToVariant (n)
        integer(handle), intent(IN)::    n
        type(VARIANT)::                fCVT_ptrToVariant
        fCVT_ptrToVariant%VT = VT_DISPATCH
        fCVT_ptrToVariant%VU%PTR_VAL = n
    end function fCVT_ptrToVariant&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="fortran"&gt;    ! Now add new sheet using AFTER argument: get the index number 
    ! of the active sheet, convert to VT before passing
    !idx = $Worksheet_GetIndex (hSheet)
    !VTidx = fCVT_Int4ToVariant (idx)
    VTidx = fCVT_ptrToVariant (hSheet)
    hSheet = Worksheets_Add(hWksheets,AFTER=VTidx,$STATUS=stat)
    count = Worksheets_GetCount(hWksheets)&lt;/LI-CODE&gt;&lt;P&gt;The code above then seems to work. You have some problems later in your example the sheet by name makes no sense as worksheet_add needs a sheet object not a name or index but I went no further.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 09 Dec 2024 15:27:05 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/F90-to-Excel-Function-Worksheet-Add/m-p/1648246#M174534</guid>
      <dc:creator>andrew_4619</dc:creator>
      <dc:date>2024-12-09T15:27:05Z</dc:date>
    </item>
    <item>
      <title>Re: F90 to Excel: Function Worksheet_Add</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/F90-to-Excel-Function-Worksheet-Add/m-p/1648380#M174544</link>
      <description>&lt;P&gt;hello Andrew_4629 and mfinnis, thanks for your suggestions! I'll try out the code and let you know.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;BTW, the thing with the 20 years is that this program is very large and I worked on it unti about 2010; it continued to be used by me ad others and worked pretty well until recently when we wanted to make some improvements. No the choice was either the learning curve of the new VisualStudio, which looks daunting, or just work with the 32 bit old version.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Though I realize that I'll have to face 64bit VisualStudio soon...&lt;/P&gt;</description>
      <pubDate>Tue, 10 Dec 2024 03:15:13 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/F90-to-Excel-Function-Worksheet-Add/m-p/1648380#M174544</guid>
      <dc:creator>mcadorno</dc:creator>
      <dc:date>2024-12-10T03:15:13Z</dc:date>
    </item>
    <item>
      <title>Re: F90 to Excel: Function Worksheet_Add</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/F90-to-Excel-Function-Worksheet-Add/m-p/1648392#M174545</link>
      <description>&lt;P&gt;just compiled your code and it worked perfectly. many thanks both to&amp;nbsp; you and mcfinnis.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;One further question regarding integer(handle);&amp;nbsp; I used integer (4)&amp;nbsp; and it works. Why do you use a pre-defined parameter?&lt;/P&gt;</description>
      <pubDate>Tue, 10 Dec 2024 05:00:21 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/F90-to-Excel-Function-Worksheet-Add/m-p/1648392#M174545</guid>
      <dc:creator>mcadorno</dc:creator>
      <dc:date>2024-12-10T05:00:21Z</dc:date>
    </item>
    <item>
      <title>Re: F90 to Excel: Function Worksheet_Add</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/F90-to-Excel-Function-Worksheet-Add/m-p/1648470#M174546</link>
      <description>&lt;P&gt;well when I made my tests I did a 64bit build and it would need to be integer(8) not integer(4), if you do not use handle you are storing up problems for if/when you use go to 64 bit.&lt;/P&gt;</description>
      <pubDate>Tue, 10 Dec 2024 12:32:26 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/F90-to-Excel-Function-Worksheet-Add/m-p/1648470#M174546</guid>
      <dc:creator>andrew_4619</dc:creator>
      <dc:date>2024-12-10T12:32:26Z</dc:date>
    </item>
    <item>
      <title>Re: F90 to Excel: Function Worksheet_Add</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/F90-to-Excel-Function-Worksheet-Add/m-p/1648524#M174548</link>
      <description>&lt;P&gt;I'll add that it is bad practice to hard-code type kinds in your declarations, especially as they are non-portable. Use of named (PARAMETER) constants is a much better method.&lt;/P&gt;</description>
      <pubDate>Tue, 10 Dec 2024 19:32:35 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/F90-to-Excel-Function-Worksheet-Add/m-p/1648524#M174548</guid>
      <dc:creator>Steve_Lionel</dc:creator>
      <dc:date>2024-12-10T19:32:35Z</dc:date>
    </item>
  </channel>
</rss>

