• Problem on Excel to Word VBA (UK/Excel/97)

    Home » Forums » AskWoody support » Productivity software by function » Visual Basic for Applications » Problem on Excel to Word VBA (UK/Excel/97)

    Author
    Topic
    #360808

    Currently running an excel workbook containing all data required to make up word documents.
    So far, the code opens word, creates new doc based on template location specified in a cell and then proceeds to transfer selected datatables and coded text into the word document at selected locations.
    Just got a problem at the moment with the following code:

    With WordApp
    .Application.Visible = True
    With .Selection
    ‘.InsertBreak Type:=wdPageBreak -problem code will not insert a page break
    .typeParagraph
    .Font.Size = 12
    .Font.Bold = True
    .Font.Italic = True
    ‘.Font.ColorIndex = wdBlue – problem code will not change text to blue
    .ParagraphFormat.Alignment = 0

    The problem lines I have commented out for now. In essence, the code is in a “do until loop” so that at the start of each loop I want to insert a page break in the word document at the last position, before continuing with the copypasting. Also requested is to type the first bits of text in Blue color (not my choice).

    I have tried using HPageBreak to insert the page break but to no avail.
    I have also tried vbBlue for the text color but again no success.

    Thanks in advance.

    Alan

    Viewing 0 reply threads
    Author
    Replies
    • #544141

      Hi Alan

      I had a similar problem once the other way around from Word to Excel. I had to use the fully qualified path for each command instead of a with/end with construction and then it run smoothly.

      hedgehog

      • #544253

        Hedgehog,
        Thanks for the tip. For now it doesn’t seem to want to know but I think I may have a ‘bodge-it’ solution – create a couple of lines macro in word to insert the page break, or change the font to blue, then call the macro by name from within the Excel code. So far it gets around the problem, but I’d really appreciate any help on not having to put a macro in the word template.
        Thanks again.
        Alan

    Viewing 0 reply threads
    Reply To: Problem on Excel to Word VBA (UK/Excel/97)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: