Macro from Excel not performing Word Actions

smit3446

New Member
Joined
Nov 16, 2015
Messages
46
I have a macro that is performing otherwise fine except for this one issue.

My VBA code is running in an Excel macro which calls a word document to be opened and pasted into another "template" word doc. The core macro is working fine, it's correctly pasting the contents into the template. However, when the template document is opened, it isn't allowing me to access the Ribbon and therefore I'm not able to perform some of the editing actions I want to accomplish.

Here is a sample of my code:
Code:
    Dim path As String    Dim folder As String
    Dim fileName As String
    Dim directory As String
    Dim Company As String
    Dim event_ As String
    Dim date_ As String
    Dim i As Integer
    Dim reinsurers As Integer
    Dim appWord As Object
    Set appWord = CreateObject("Word.Application")
        
    reinsurers = Range("A3", Range("A3").End(xlDown)).Rows.Count
    Company = Worksheets("Inputs").Range("G3").Value
    date_ = Worksheets("Inputs").Range("G4").Value
    event_ = Worksheets("Inputs").Range("G5").Value
    
    
    appWord.Visible = True
    appWord.Documents.Open "R:\Reinsurers\2. Bios\Reinsurer Bio Template.docx"
    appWord.Selection.MoveDown Unit:=wdLine, Count:=1




        With appWord.Selection.Find
        .Text = "[Company]"
        .Replacement.Text = Company
        .Forward = True
        .Wrap = wdFindAsk
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
        End With
    appWord.Selection.Find.Execute Replace:=wdReplaceAll   

i = 3

    Do While i < reinsurers + 3
    
    path = "R:\Reinsurers\2. Bios\"
    folder = Worksheets("Inputs").Range("C" & i).Value
    fileName = Worksheets("Inputs").Range("B" & i).Value
    directory = path & folder & "\" & fileName
    
    
    If Worksheets("Inputs").Range("C" & i).Value <> Worksheets("Inputs").Range("C" & i - 1).Value Then
    
        appWord.Documents("Reinsurer Bio Template.docx").Activate
        appWord.Selection.InsertBreak Type:=wdPageBreak
        appWord.Selection.TypeText Text:=folder & vbCr

Any help would be greatly appreciated. Thank you!
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
There isn't enough code there to know what's going on. That said, you can't manually edit the document while you macro is running.
 
Upvote 0

Forum statistics

Threads
1,223,246
Messages
6,170,999
Members
452,373
Latest member
TimReeks

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top