Excel Automation - Using Goto() Method

I want to put specific cell top left of worksheet through moving scrolls.
So I searched, in some VBA document, found _Application::Goto() Method.
But I don't know how to use in C++ environment.
It's so hard to find documents about Excel Automation in "MFC C++" environment.

This is my code.

m_Range = m_Range.Find(COleVariant(_T(m_InputNameStr)), vOpt, xlValues,
vOpt, vOpt, xlNext, vOpt, vOpt, vOpt);

m_App.Goto(COleVariant(m_Range), gotoScrollTrue);


Actually, I have no idea with the first parameter.
Excel.h code says it should be "VARIANT& Reference"(void Goto(const VARIANT& Reference, const VARIANT& Scroll)), and MSDN says it can be "Range object" (https://msdn.microsoft.com/library/office/ff839232(v=office.14).aspx)

but i don't know what should I use.

P.S
I think it doesn't matter whether it goes to top left or center of the worksheet.
I just want to put that cell somewhere people can easily find. Because that cell is gonna be a result of search.
If there's any good method instead of Goto() method, please let me know.

I know I'm clueless but any advice would be help.
Last edited on
Its difficult to find info on using Excel (or any Microsoft Office product) with C++ because so few folks do it. Most folks who 'automate' Excel use Miocrosoft specific coding tools such as .NET in one form or another.

That said, I work with Excel, Word, and Access using C++ all the time, but I doubt you would be interested in what I do. I don't use MFC or any class frameworks. I write all the low level OLE/COM automation code to do what I need which I've put in mini-libraries.

I've gotta say that from your description above I'm a bit fuzzy on what you are trying to do.
Thank you for your kind reply. Now I finally know the reason why I messed it up.

I think what you said would be pretty good solution but unfortunately it will probably be difficult for me to switch to another tools from MFC. Because I'm working with some hardware machine and since I'm a newbie Windows programmer, just modifying Excel part. I mean I'm not sure if I can write the whole code again with another tool.

Well, what I'm trying to do is "Search" function just as Excel do. If you enter the value and press Search button, matched cell is placed in middle of the worksheet. But for me, it doesn't necessarily have to be placed in middle of the worksheet. It's OK if the cell goes to top left of the worksheet.

I'm sorry that I can't explain well.
Last edited on
Topic archived. No new replies allowed.