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

    How to get worksheet name?

    Hi,
    I'm having trouble locating the worksheet name ,
    My code uses as following:
    Code:
    IDispatch* xlSheet; //<--get xlSheet ok
    
       VARIANT result4;
        VariantInit(&result4);
        AutoWrap(DISPATCH_PROPERTYGET, &result4, xlSheet, L"Name",0); 
        if (result4.vt == VT_BSTR)
        {
    	  
        }
    Can you tell me where did I go wrong?
    because from this post says it takes no arguments so I set the number of arguments to 0 .

    The error I get is :

    Name:  bug1.jpg
Views: 1100
Size:  10.3 KB

    When I use the code snippets from above post, it runs fine.
    Did I misspelled the property name "NAME"?

    Thanks you!
    Last edited by Dang.D.Khanh; July 24th, 2021 at 04:54 PM.

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: How to get worksheet name?

    The code you post is different from the code you are showing woth the error. Not sure what you are doing.

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

    Re: How to get worksheet name?

    Quote Originally Posted by Dang.D.Khanh View Post
    Hi,
    I'm having trouble locating the worksheet name ,
    My code uses as following:
    ...
    Can you tell me where did I go wrong?
    because from this post says it takes no arguments so I set the number of arguments to 0 .
    You refer to this Microsoft sample code
    But did you debug this code? particularly, what does the
    Code:
    hr = pDisp->GetIDsOfNames(IID_NULL, &ptName, 1, LOCALE_USER_DEFAULT, &dispID);
    return? Is it S_OK or some error code?
    Victor Nijegorodov

  4. #4
    Join Date
    Jun 2021
    Posts
    51

    Re: How to get worksheet name?

    Hi Sirs,
    this code: hr = pDisp->GetIDsOfNames return S_OK,
    I checked but there is no more information to see in IDispatch, debugging is quite difficult.
    So maybe I should go back to MFC, I'll try again when I'm more familiar with it.
    Temporary problem solved.
    Last edited by Dang.D.Khanh; July 25th, 2021 at 07:41 PM.

  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 get worksheet name?

    Quote Originally Posted by Dang.D.Khanh View Post
    Hi Sirs,
    this code: hr = pDisp->GetIDsOfNames return S_OK,
    I checked but there is no more information to see in IDispatch, debugging is quite difficult.
    So maybe I should go back to MFC, I'll try again when I'm more familiar with it.
    Temporary problem solved.
    You don't need to go deeper than AutoWrap itself. Gou should, however check what other function calls return!
    Victor Nijegorodov

  6. #6
    Join Date
    Jun 2021
    Posts
    51

    Re: How to get worksheet name?

    Quote Originally Posted by VictorN View Post
    You don't need to go deeper than AutoWrap itself. Gou should, however check what other function calls return!
    Thanks sir, I will keep it in mind.

Tags for this Thread

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