Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / October 2005

Tip: Looking for answers? Try searching our database.

Excel API from VC++ .NET

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
bill - 28 Sep 2005 15:28 GMT
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.

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
Uday Takbhate [MSFT] - 29 Sep 2005 02:09 GMT
You can use the following namespace.

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

Regards,
Uday Takbhate [MSFT]
--------------------
>From: "bill" <wgrigg@draper.com>
>Newsgroups: microsoft.public.dotnet.framework.interop
[quoted text clipped - 7 lines]
>Content-Type: text/plain; charset="iso-8859-1"
>X-Trace: posting.google.com 1127917713 11541 127.0.0.1 (28 Sep 2005
14:28:33 GMT)
>X-Complaints-To: groups-abuse@google.com
>NNTP-Posting-Date: Wed, 28 Sep 2005 14:28:33 +0000 (UTC)
>User-Agent: G2/0.2
>X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1;
.NET CLR 1.1.4322),gzip(gfe),gzip(gfe)
>Complaints-To: groups-abuse@google.com
>Injection-Info: o13g2000cwo.googlegroups.com; posting-host=192.80.95.242;
>   posting-account=7vU72gwAAADXwqi6olnMjCDpkupdCL0H
>Path:
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
>Xref: TK2MSFTNGXA01.phx.gbl microsoft.public.dotnet.framework.interop:9877
>X-Tomcat-NG: microsoft.public.dotnet.framework.interop
[quoted text clipped - 30 lines]
>
>Bill
Bill - 29 Sep 2005 15:31 GMT
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
http://www.dotnetnewsgroups.com
Uday Takbhate [MSFT] - 30 Sep 2005 01:40 GMT
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]
--------------------
>From:     Bill <wgrigg@draper.com>
>References: <ywmLLKJxFHA.628@TK2MSFTNGXA01.phx.gbl>
[quoted text clipped - 26 lines]
>Sent via .NET Newsgroups
>http://www.dotnetnewsgroups.com
Bill - 30 Sep 2005 15:18 GMT
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
http://www.dotnetnewsgroups.com
Uday Takbhate [MSFT] - 05 Oct 2005 21:44 GMT
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]
--------------------
>From:     Bill <wgrigg@draper.com>
>References: <IpW9geVxFHA.3020@TK2MSFTNGXA01.phx.gbl>
[quoted text clipped - 47 lines]
>Sent via .NET Newsgroups
>http://www.dotnetnewsgroups.com
Uday Takbhate [MSFT] - 06 Oct 2005 16:35 GMT
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]
--------------------
>X-Tomcat-ID: 634164860
>References: <IpW9geVxFHA.3020@TK2MSFTNGXA01.phx.gbl>
<#QObSncxFHA.1132@TK2MSFTNGP10.phx.gbl>
>MIME-Version: 1.0
>Content-Type: text/plain
[quoted text clipped - 97 lines]
>>Sent via .NET Newsgroups
>>http://www.dotnetnewsgroups.com

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.