CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jun 2021
    Posts
    51

    How to Add new sheet to the end?

    Hi,
    I have searched a lot of post but still haven't found an answer, the code I use is as follows:

    HTML Code:
    Excel::WorksheetsPtr ws = Worksheets->GetItem(Worksheets->Count); <<-- last worksheet
    
    //Syntax:  IDispatchPtr Sheets::Add ( const _variant_t & Before, const _variant_t & After, 
    //                                    const _variant_t & Count, const _variant_t & Type, long lcid );
    Worksheets->Add(vtMissing, ws,  <<-- add to last
                                1, vtMissing, (long)Excel::xlWorksheet));
    This doc say:

    HTML Code:
     After	Optional	Variant	An object that specifies the sheet after which the new sheet is added.
    but how to convert IDispatchPtr to _variant_t ?

    Thanks you!
    Last edited by Dang.D.Khanh; July 2nd, 2021 at 03:30 AM. Reason: Missing Tag c++,excel

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: How to Add new sheet to the end?

    Quote Originally Posted by Dang.D.Khanh View Post
    ...
    but how to convert IDispatchPtr to _variant_t ?

    Thanks you!
    Did you try ( from https://docs.microsoft.com/en-us/cpp...?view=msvc-160 )
    Code:
    _variant_t(
       IDispatch* pDispSrc,
       bool fAddRef = true
    ) throw( );
    Victor Nijegorodov

  3. #3
    Join Date
    Jun 2021
    Posts
    51

    Re: How to Add new sheet to the end?

    Hi Sir,
    Thanks for the reply!
    I'm having issues with compiling some other lines of code so I can't run the project.
    I will try to compile it and come back soon
    Last edited by Dang.D.Khanh; July 3rd, 2021 at 10:44 AM.

  4. #4
    Join Date
    Jun 2021
    Posts
    51

    Re: How to Add new sheet to the end?

    Hi Sir,
    This is exactly what I need. My problem is solved !

  5. #5
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: How to Add new sheet to the end?

    Glad you have solved it!
    Victor Nijegorodov

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured