Thread: Changing Font (Word COM)

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

    Changing Font (Word COM)

    Hi, I wanted to change the font in a dynamically created word document, I am using Visual C++ and MFC, I am having problems with it, it's the first time i have used a COM, and have managed to cobble together a document from the Microsoft Online Help, but changing the font is eluding me.

    Code:
    							Selection oSel;
    							_Font oFont = oSel.GetFont();
    							oFont.SetName("Tahoma");
    							oFont.SetSize(16);
    							oSel.SetFont(oFont);
    
    							
    							oSel = oApp.GetSelection();
    							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.ReleaseDispatch();
    that is the snippet of code concerning the font and field editing, am I wrong in trying to change the font before typing anything.

    The word document can be created without the fint code in there, but the font code produces an "Invalid Parameter" fault.

    Thanks in advance.
    Compiler == Visual C++ 6.0
    "Come Out Fighting."

  2. #2
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    Code:
    Selection oSel;
    oSel = oApp.GetSelection();
    _Font oFont = oSel.GetFont();

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. brace-enclosed error
    By jdc18 in forum C++ Programming
    Replies: 53
    Last Post: 05-03-2007, 05:49 PM
  2. problem with my font manager
    By hannibar in forum C Programming
    Replies: 1
    Last Post: 03-07-2006, 08:03 AM
  3. char copy
    By variable in forum C Programming
    Replies: 8
    Last Post: 02-06-2005, 10:18 PM
  4. Wrong Output
    By egomaster69 in forum C Programming
    Replies: 7
    Last Post: 01-28-2005, 06:44 PM
  5. Changing font using Word OLB
    By UnclePunker in forum Windows Programming
    Replies: 0
    Last Post: 07-07-2004, 05:47 AM