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:
Any help would be greatly appreciated. Thank you!
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!