Solved

Creating MsWord or Powerpoint document

Posted on 2001-07-26
8
198 Views
Last Modified: 2013-11-25
Hi there,
Is it easy to create a microsoft word document (or powerpoint) with text and image from within Visual C++ / MFC? How?
If not from MFC, then, how?
Thanks,
cshwong
0
Comment
Question by:cshwong
  • 4
  • 3
8 Comments
 
LVL 12

Expert Comment

by:migel
Comment Utility
Hi!
you have to use MS_OFFICE COM objects:
to use it you have to import TLB shipped with MSoffice :

//for example for Excell:
#import "..\excel\mso97.dll" no_namespace rename("DocumentProperties", "DocumentPropertiesXL")
#import "..\excel\vbeext1.olb" no_namespace  rename("_CommandBars", "CommandBars")
#import "..\excel\excel8.olb" rename("DialogBox", "DialogBoxXL") rename("RGB", "RBGXL") rename("DocumentProperties", "DocumentPropertiesXL") rename("_CommandBars", "CommandBars") no_dual_interfaces
using namespace Excel;

and later use it:
for example this code opens excel APP and run macro

     CoInitialize(NULL);
     _ApplicationPtr pXL;
     
    try {
          SetSpyHook(TRUE);
          pXL.CreateInstance(L"Excel.Application");
          pXL->Visible = VARIANT_TRUE;
          WorkbooksPtr pBooks = pXL->Workbooks;
          char szPath[_MAX_PATH];
          _getcwd(szPath, _MAX_PATH);
          if (szPath[strlen(szPath)-1] != '\\')
               strcat(szPath, "\\");
          strcat(szPath, "test.xla");
          _WorkbookPtr pBook  = pBooks->Open(_bstr_t(szPath));
          pXL->Run(_variant_t("test.xla!init_app"));
          }
     catch(_com_error &e)
          {
....
          }

0
 
LVL 12

Expert Comment

by:migel
Comment Utility
SetSpyHook(TRUE); - delete this line (it is just working code remains)
0
 

Author Comment

by:cshwong
Comment Utility
Thanks,
But, now to put text and position an image in an empty Word document?  
0
 
LVL 12

Expert Comment

by:migel
Comment Utility
Hi You can look at TLB methods and find something usefull :-)
you can use InsertBefore to insert text at specific position in the document
and for bitmap you can add it in the Shapes collection
// in the basic (VBA)
ActiveDocument.Shapes.AddOLEObject _
    FileName:="c:\my documents\MyDrawing.bmp", _
    LinkToFile:=True

Also I recommend you open VBA editor in the Word and open opbject inspector here you found ALL methods provided by MSOffice Objects and also you found some usefull examples how to use it in the VBA (code for C++ looks same)
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

Author Comment

by:cshwong
Comment Utility
Thanks to migel,

However, I am a dummy of COM.

I can't find mso97.dll in my harddisks.  What can I do?

I try VC++'s "tools"\"OLE/COM Object Viewer" and I am confused by the things.  I searched related topics in MSDN but I see many articles and just don't know where to start.  I really want to do it quick.

In MsWord, I cannot find "VBA editor"'s "Object Inspector".  I can only find "Visual Basic Editor"'s "Object Browser".

I would be grateful if you can help me further by listing the steps I should do in order to incoporate your code. [ I think I am an experienced MFC programmer, but is dummy to Visual Basic and COM ]

However, if you think that I should give up, please let me know.  I'll still send you the points.

Thanks anyway,
cshwong


0
 
LVL 12

Accepted Solution

by:
migel earned 100 total points
Comment Utility
Hi!
Mso97.dll is the COM library for MSOffice 97.
if you have another version you need diffferent dll
for example for office 2000 you need:
mso9.dll
MSWORD9.OLB
also look at MSDN
Microsoft Office 2000 Developer Object Model Guide
and related topics

0
 

Author Comment

by:cshwong
Comment Utility
Thanks to migel,

However, I am a dummy of COM.

I can't find mso97.dll in my harddisks.  What can I do?

I try VC++'s "tools"\"OLE/COM Object Viewer" and I am confused by the things.  I searched related topics in MSDN but I see many articles and just don't know where to start.  I really want to do it quick.

In MsWord, I cannot find "VBA editor"'s "Object Inspector".  I can only find "Visual Basic Editor"'s "Object Browser".

I would be grateful if you can help me further by listing the steps I should do in order to incoporate your code. [ I think I am an experienced MFC programmer, but is dummy to Visual Basic and COM ]

However, if you think that I should give up, please let me know.  I'll still send you the points.

Thanks anyway,
cshwong


0
 
LVL 23

Expert Comment

by:Roshan Davis
Comment Utility
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Answered by : migel

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Roshan Davis
EE Cleanup Volunteer
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now