Thread: Word COM problem

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    ResurgentBarbecue UnclePunker's Avatar
    Join Date
    May 2002
    Posts
    128

    Word COM problem

    Hi, I am trying to use the Word COM to create a document, orient it to landscape, change font to Arial, add some merge fields, attach a data source and then save it, I have a hit a problem with the font, here is my code:

    Code:
    //Start Word.
    	if(!oApp.CreateDispatch("Word.Application",NULL))
    	{
    		AfxMessageBox("Unable to start Word.");
    		return;
    	}
    
    	//Create a new mail merge document.
    	oDocs = oApp.GetDocuments();
    	oDoc = oDocs.Add(vOpt, vOpt, vOpt, vOpt);  //for Word 2000
    	MailMerge oMerge = oDoc.GetMailMerge();
    	PageSetup oSet = oDoc.GetPageSetup();
    
    	_Font oFont;
    
    	oSet.SetOrientation(1);
    
    	//Insert Fields into the document.
    	oMMFields = oMerge.GetFields();
    
    	Selection oSel;	
    
    	oSel.TypeText("Jobname: ");
    	AddFieldAtSelection("jobname");
    	oSel = oApp.GetSelection();
    	oSel.TypeParagraph();
    	oSel.TypeText("Job No: ");
    	AddFieldAtSelection("jobno");
    	oSel = oApp.GetSelection();
    	oSel.TypeParagraph();
    	oSel.TypeText("From: ");
    	AddFieldAtSelection("start");
    	oSel.TypeText("   ");
    	oSel = oApp.GetSelection();
    	oSel.TypeText("To: ");
    	AddFieldAtSelection("end");
    
    	oSel = oApp.GetSelection();
    	oFont = oSel.GetFont();
    	oFont.SetName("Arial");
    	oFont.SetSize(24);
    	oSel.SetFont(oFont);
    
    
    	oSel.ReleaseDispatch();
    
    	oMerge.SetMainDocumentType(0); //1=wdMailingLabels
    	oMerge.OpenDataSource(m_dataname, vOpt, vOpt, vOpt, vOpt, vOpt, vOpt, vOpt, vOpt, vOpt, vOpt, vOpt, vOpt, vOpt);
    
    	//oDoc.Close(vFalse, vOpt, vOpt);
    	//oDoc.ReleaseDispatch();
    	oApp.SetVisible(TRUE);
    	oDocs.ReleaseDispatch();
    	oApp.ReleaseDispatch();
    this is my first time using COM and I am finding it very confusing, so please be gentle.

    Cheers.
    Last edited by UnclePunker; 01-06-2005 at 09:42 AM.
    Compiler == Visual C++ 6.0
    "Come Out Fighting."

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. seg fault at vectornew
    By tytelizgal in forum C Programming
    Replies: 2
    Last Post: 10-25-2008, 01:22 PM
  2. Problem either on display method or structure..
    By DarrenY in forum C Programming
    Replies: 2
    Last Post: 09-04-2005, 08:16 AM
  3. New problem [Beginner]
    By Vintik in forum C++ Programming
    Replies: 2
    Last Post: 08-18-2005, 11:33 PM
  4. Passing structures to a function
    By earth_angel in forum C++ Programming
    Replies: 5
    Last Post: 07-13-2005, 06:13 AM
  5. Wrong Output
    By egomaster69 in forum C Programming
    Replies: 7
    Last Post: 01-28-2005, 06:44 PM