Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7014541
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:32:04+00:00 2026-05-27T22:32:04+00:00

If someone knows how to go from Excel::Window pointer to real value in opened

  • 0

If someone knows how to go from Excel::Window pointer to real value in opened Excel cell, please let me know.
Here is the task conditions:
– Excel is currently running in one single window with one workbook on one sheet
– some cells have data (to simplify let’s say only one cell[1,1] has data, which is “a”)
The question is how to find out that only one cell has data, and cell is [1,1] and the data is “a”.
To start with here is a code snippet:

int main( int argc, CHAR* argv[])
{
   CoInitialize( NULL );
   HWND excelWindow = FindWindow(L"XLMAIN", NULL);
   EnumChildWindows(excelWindow, (WNDENUMPROC) EnumChildProc, (LPARAM)1);
   return 0;
}
BOOL CALLBACK EnumChildProc(HWND hwnd, LPARAM)
{
   WCHAR szClassName[64];
   if(GetClassNameW(hwnd, szClassName, 64))
   {
      if(_wcsicmp(szClassName, L"EXCEL7") == 0)
      {
         Excel::Window* pWindow = NULL;
         HRESULT hr = AccessibleObjectFromWindow(hwnd, OBJID_NATIVEOM, __uuidof(Excel::Window), (void**)&pWindow);
         if(hr == S_OK)
         {
            // Here we need to answer the question using pWindow                
            pWindow->Release();
         }
         return false;     
      }     
   }
   return true;
}  
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T22:32:05+00:00Added an answer on May 27, 2026 at 10:32 pm

    Here is code finally used:

    #include <windows.h>
    #include <oleacc.h>
    #import "C:\Program Files (x86)\Common Files\microsoft shared\OFFICE14\MSO.DLL" no_implementation rename("RGB", "ExclRGB") rename("DocumentProperties", "ExclDocumentProperties") rename("SearchPath", "ExclSearchPath")
    #import "C:\Program Files (x86)\Common Files\microsoft shared\VBA\VBA6\VBE6EXT.OLB" no_implementation
    #import "C:\Program Files (x86)\Microsoft Office\Office14\EXCEL.EXE" rename("DialogBox", "ExclDialogBox") rename("RGB", "ExclRGB") rename("CopyFile", "ExclCopyFile") rename("ReplaceText", "ExclReplaceText")
    #include <string>
    using std::string;
    
    BOOL CALLBACK EnumChildProc(HWND hwnd, LPARAM)
    {
        WCHAR szClassName[64];
        if(GetClassNameW(hwnd, szClassName, 64))
        {
            if(_wcsicmp(szClassName, L"EXCEL7") == 0)
            {
                //Get AccessibleObject
                Excel::Window* pWindow = NULL;
                IDispatch* pXlSheet = NULL;
                HRESULT hr = AccessibleObjectFromWindow(hwnd, OBJID_NATIVEOM, __uuidof(Excel::Window), (void**)&pWindow);
                if(hr == S_OK)
                {               
                    try {
                        VARIANT result;
                        VariantInit(&result);
                        AutoWrap(DISPATCH_PROPERTYGET, &result, pWindow, L"ActiveSheet", 0);
                        pXlSheet = result.pdispVal;
                        _variant_t sheetName;
                        VariantInit(&sheetName);
                        if ((pXlSheet != NULL) && (pXlSheet != (IDispatch*)0xCCCCCCCC))
                        AutoWrap(DISPATCH_PROPERTYGET, &sheetName, pXlSheet, L"Name", 0); 
    
                        // get cell which you need
                        string location = "C5"; 
                        location += ":" + location; // cell is a range with the same start/end cells
                        OLECHAR *sOleText=new OLECHAR[location.length()+1];
                        mbstowcs(sOleText,location.c_str(),location.length()+1);
    
                        IDispatch *pXlRange; // Get Range from Sheet
                        VARIANT parm;
                        parm.vt = VT_BSTR;
                        parm.bstrVal = ::SysAllocString(sOleText); 
                        VARIANT result;
                        VariantInit(&result);
                        AutoWrap(DISPATCH_PROPERTYGET, &result, pXlSheet, L"Range", 1, parm);
                        VariantClear(&parm);
                        pXlRange = result.pdispVal;
                        Excel::RangePtr cell = pXlRange;
                        Excel::CharactersPtr ptr = cell->Characters;
                        _bstr_t text = ptr->Text; // here is needed text
                    } catch (...) { }
                }
                return false;     // Stops enumerating through children
            }       
        }
        return true;
    }
    
    void main( int argc, CHAR* argv[])
    {
        CoInitialize(NULL);
        HWND excelWindow = FindWindow(L"XLMAIN", NULL);
        EnumChildWindows(excelWindow, (WNDENUMPROC) EnumChildProc, (LPARAM)1);
        CoUninitialize();
    }
    

    The AutoWrap() function has been taken from http://support.microsoft.com/kb/216686/en-us?fr=1, while the initial sample from http://www.northatlantawebdesign.com/index.php/2009/07/15/access-microsoft-excel-2007-com-api-through-microsoft-active-accessibility/
    Thanks to all who helped.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does someone know how to export an excel file (csv, xls and xlsx) from
I need the advice from someone who knows Java very well and the memory
Does someone know a wrapper which would allow SQLite to load its data from
I write this post to know if someone knows how to do this: I
Someone knows how to put an icon in a eVB 3 application, because i
Does someone knows if it's possible to dynamically create a call chain and invoke
Does someone knows how can I capture my computer screen to a video file?
I wonder if someone knows if there is a pre-made solution for this: I
I have this problem I'm hoping someone knows the answer to. I have an
I find this question a little tricky. Maybe someone knows an approach to answer

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.