VB6 MS Word Font Color automation
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: VB6 MS Word Font Color automation

  1. #1
    Join Date
    Jan 2013
    Posts
    48

    VB6 MS Word Font Color automation

    I need to insert some formatted text into MS Word document. I started MS Word Macro and entered this code:
    Code:
        Selection.TypeText Text:="Test Macro Color Red "
        Selection.Font.Size = 20
        Selection.TypeText Text:="Size Changed "
        Selection.Font.ColorIndex = wdGreen
        Selection.TypeText Text:="ColorIndex set "
        Selection.Font.Bold = True
        Selection.TypeText Text:="Bold "
        Selection.Font.Underline = wdUnderlineSingle
        Selection.TypeText Text:="Undeline "
        Selection.Font.ColorIndex = wdRed
        Selection.TypeText Text:="TextColor set"
    When I run this macro I get what I wanted:
    Name:  TextColor.jpg
Views: 51
Size:  42.5 KB
    If I use very similar code in VB6 statement for Size and Bold work, the lines containing ColorIndex assignment and Underline do not work, produce errors:
    Name:  Error.jpg
Views: 41
Size:  49.1 KB

    How do I set the color of text and some other properties of font in Word in VB6?

    Thank you

  2. #2
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,669

    Re: VB6 MS Word Font Color automation

    The identifiers starting with wd are constants defined in the Word VBA operating environment and are not known in VB6. Try to find out their concrete values in Word, for instance by using Print statements, and use these in VB6 instead of the constant identifiers.

    Admittedly, if that really is the only problem, then I find that VB6 error message quite unclear and little helpful...
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

  3. #3
    Join Date
    Jan 2013
    Posts
    48

    Re: VB6 MS Word Font Color automation

    Before I used wd identifiers I found their values and declared public constants in a standard module. I also tried RGB. It did not work as well.
    Thank you

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This a Codeguru.com survey!


On-Demand Webinars (sponsored)