PDA

View Full Version : VBA Word Table change color and font of cell based off text in table



daniel.stron
04-01-2015, 07:11 AM
I have the below code that is taking information from an excel file and putting it in a table within a word document. I need it to keep the formatting in the first column. I have a macro in the excel file that is changing the cells in column A to wingdings l and a color (small circle). The macro below will move everything over, but not keep the formatting. Can anyone help point me in the right direction?


Sub Merge_Files_4P()


Debug.Print ActiveDocument.Range(1).Tables(1).Range.Rows(2).Cells(1).Range
Dim MyExcel As Excel.Application
Dim MyWB As Excel.Workbook
Set MyExcel = New Excel.Application
Set MyWB = MyExcel.Workbooks.Open("C:\Users\dani7844\Desktop\Automation Files\4P Automation\4P - Strategic Programs Roadmap.xlsm")




For i = 1 To 6
ActiveDocument.Range(1).Tables(1).Range.Rows(2).Cells(i).Range = MyWB.Sheets("Sheet1").Cells(2, i)
ActiveDocument.Range(1).Tables(1).Range.Rows(3).Cells(i).Range = MyWB.Sheets("Sheet1").Cells(3, i)
ActiveDocument.Range(1).Tables(1).Range.Rows(4).Cells(i).Range = MyWB.Sheets("Sheet1").Cells(4, i)
ActiveDocument.Range(1).Tables(1).Range.Rows(5).Cells(i).Range = MyWB.Sheets("Sheet1").Cells(5, i)
ActiveDocument.Range(1).Tables(1).Range.Rows(6).Cells(i).Range = MyWB.Sheets("Sheet1").Cells(6, i)
ActiveDocument.Range(1).Tables(1).Range.Rows(7).Cells(i).Range = MyWB.Sheets("Sheet1").Cells(7, i)
ActiveDocument.Range(1).Tables(1).Range.Rows(8).Cells(i).Range = MyWB.Sheets("Sheet1").Cells(8, i)
Next i




MyWB.Close False
Set MyExcel = Nothing
Set MyWB = Nothing


End Sub