change the Style for a certain number of lines in a Word doc from Excel VBA (2010)

  • i have done in Word VBA successfully (basically, change the Style for a certain number of lines):


    Code
    Dim myRange As Range
    Set myRange = ActiveDocument.Range(ActiveDocument.Range.Start, ActiveDocument.Range.Start)
    myRange.Select
        Selection.MoveDown Unit:=wdLine, Count:=4
        Selection.MoveDown Unit:=wdLine, Count:=2, Extend:=wdExtend
        Selection.Style = ActiveDocument.Styles("No Spacing")


    and I would like to add to the following Excel VBA (opening Word and coping out text works well):


    Code
    Set WordApp = CreateObject("word.Application")
       WordApp.Documents.Add
       With WordApp.Selection
        .typeParagraph
        .typetext Text:=text2Prtint
        .WholeStory
        .Style = ("Normal")
        '????


    ???


    thank you.

  • Re: change the Style for a certain number of lines in a Word doc from Excel VBA (2010


    Off the top of my head, I would first declare myRange as an Object for the VBA code.
    Then, just add the qualification (to the first bit of code) that ActiveDocument is a property of the application object, so that ActiveDocument would be replaced with wordApp.ActiveDocument throughout.

  • Re: change the Style for a certain number of lines in a Word doc from Excel VBA (2010


    thank you...


    i'll give it a try...


    and would you have an example/www for me to review the concept?


    thanks.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!