all groups > dotnet interop > september 2005 >
You're in the

dotnet interop

group:

Excel API from VC++ .NET


Excel API from VC++ .NET bill
9/28/2005 7:28:25 AM
dotnet interop:
I cannot find any examples of doing Excel automation from a VC++ .Net
environment. Does anyone ay least know what the namespace should be to
expose the Excel app? i.e.


using namespace System::?????????????????

Someone on another group suggested the following:

<<<<For managed, you use the same manage PIAs (Primary Interop
Assemblies) and namespaces as you would for C# or VB.NET.

Are you doing managed C++ or native (aka unmanaged) C++?

For managed, you use the same manage PIAs (Primary Interop Assemblies)
and namespaces as you would for C# or VB.NET.
[quoted text, click to view]

This is nice to know but I am doing managed code and I tried adding the
following references:

Excel
Microsoft.Office.Core


However, I cannot seem to figure out how to declare an Excel app from
C++. I also notice that intellisense works with all the references
except for Excel. Any pointers to examples that you can share. I have
been googling around in my spare time but cannot find anything useful
(so far).


TIA,


Bill
RE: Excel API from VC++ .NET udayt NO[at]SPAM microsoft.com
9/29/2005 1:09:55 AM
You can use the following namespace.

using namespace Microsoft::Office::Interop::Excel;

Regards,
Uday Takbhate [MSFT]
--------------------
[quoted text, click to view]
TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfeed00.sul.t-online.de!t-onli
ne.de!border2.nntp.dca.giganews.com!nntp.giganews.com!postnews.google.com!o1
3g2000cwo.googlegroups.com!not-for-mail
[quoted text, click to view]
RE: Excel API from VC++ .NET Bill
9/29/2005 7:31:27 AM
Uday,

I have already tried

"using namespace Microsoft::Office::Interop::Excel"

It does not accept "Interop". The only intellisense option shown is
"core()"

Bill

--
Sent via .NET Newsgroups
RE: Excel API from VC++ .NET udayt NO[at]SPAM microsoft.com
9/30/2005 12:40:49 AM
It is true that intellisense does not show up the "Interop" option but
indeed you can use it.
Try once again.

Regards,
Uday Takbhate [MSFT]
--------------------
[quoted text, click to view]
RE: Excel API from VC++ .NET Bill
9/30/2005 7:18:24 AM
Uday,

I think part of my problem was that I did not have a reference to the MS
Office com object. Anyway after adding that the following did compile:

"using namespace Microsoft::Office::Interop::Excel;"

This created a namespace conflict with the following:

"using namespace System::Windows::Forms;"

The form could not be declared because the "Application" part thought is
was an Excel application. Anyway, I solved that problem and now I do not
know how to delcare the Excel application. The following code:

Microsoft::Office::Interop::Excel::Application* ap;
......
Microsoft::Office::Interop::Excel::Application::Run(ap);

produces the following error message:

"error C2660: 'Microsoft::Office::Interop::Excel::_Application::Run' :
function does not take 1 arguments"


I cannot of course figure out what the call to run the Excel application
looks like because Intellisense shows nothing and there is no
documentation that I can find.

Help,

Bill



--
Sent via .NET Newsgroups
RE: Excel API from VC++ .NET udayt NO[at]SPAM microsoft.com
10/5/2005 8:44:36 PM
Bill,

Intellisense will not show anything in this case.

I guess you are experiencing the following error in the WinMain() right?
If yes then try something like..

int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
System::Threading::Thread::CurrentThread->ApartmentState =
System::Threading::ApartmentState::STA;
System::Windows::Forms::Application::Run(new Form1());

...............
}

Because in WinMain() the Run() method of Form is expected to be called not
that of Excel::Application.

If you are trying to invoke the Run method on Excel::Application then refer
to the following link for more information of this method.
http://msdn.microsoft.com/library/en-us/vbaac11/html/acmthRun_HV05186408.asp

Run method is used to call a macro defined in the excel workbook from using
excel object model.

There is very little documentation available on automation using C++ or
VC++ as most of the MSDN documents assume automation using visual basic

Regards,
Uday Takbhate [MSFT]
--------------------
[quoted text, click to view]
RE: Excel API from VC++ .NET udayt NO[at]SPAM microsoft.com
10/6/2005 12:00:00 AM
I guess following articles will be helpful to you.

INFO: Using Visual C++ to Automate Office
http://support.microsoft.com/kb/q238972/

Office Automation Using Visual C++
http://support.microsoft.com/kb/q196776/

FILE: B2CSE.exe Converts Visual Basic Automation Code to Visual C++
http://support.microsoft.com/kb/216388/EN-US/

Automating Microsoft Office 97 and Microsoft Office 2000 (C++)
http://www.msdn.microsoft.com/library/default.asp?url=/library/en-us/dno2kta
/html/offaut.asp

Any further queries? Feel free to ask.

Regards,
Uday Takbhate [MSFT]
--------------------
[quoted text, click to view]
AddThis Social Bookmark Button