Solved

Creating MsWord or Powerpoint document

Posted on 2001-07-26
8
203 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 12

Expert Comment

by:migel
ID: 6321229
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
ID: 6321232
SetSpyHook(TRUE); - delete this line (it is just working code remains)
0
 

Author Comment

by:cshwong
ID: 6321401
Thanks,
But, now to put text and position an image in an empty Word document?  
0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
LVL 12

Expert Comment

by:migel
ID: 6321585
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
 

Author Comment

by:cshwong
ID: 6325255
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
ID: 6325722
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
ID: 6325736
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
ID: 9490553
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
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…

737 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