A
Alex St-Pierre
Hi, I would like to use excel property in Word VBA.
The problem I have is that I format Word Table using Table in Excel and
would like to adjust to table depending of all cells format in excel.
So, I open the Excel workbook and copy a table value to word. I would like
to refer to Excel cells borders and text style (ex: bold) to be able to
adjust word table but doesn't know how ?
Dim appExcel As Object
Dim wbExcel As Object
Dim rngExcel as Range
Dim tbl As Word.Table
Dim DocWord1 As Word.Document
Dim strData as String
Set DocWord1 = AppWord.ActiveDocument
PathExcel = "table.xls"
Set appExcel = GetObject(, "Excel.Application")
Set tbl = DocWord1.Tables(2)
Set wbExcel = appExcel.Workbooks(PathExcel)
Set rngExcel = wbExcel.Sheets("table1.1").Range("Table1_1")
Set tbl = DocWord1.Tables(2)
DerLigneExcel = rngExcel.Rows.Count
DerLigneWord = tbl.Rows.Count
j = DerLigneExcel - DerLigneWord
For k = 1 To j
tbl.Rows.Add
Next k
For k = 1 To -j
tbl.Cell(5, 1).Select
Selection.SelectRow
Selection.Rows.Delete
Next k
With tbl
For i = 1 To tbl.Rows.Count
For j = 1 To tbl.Columns.Count
strData = rngExcel.Cells(i, j)
strData = Format(strData, "#,##0;(#,##0)")
.Cell(i, j).Range.Text = strData
'I would like to say:
' If rngExcel.Cells(i, j).Borders(x1EdgeTop).LineStyle = x1continue Then
' etc.
' End If 'Also, if this work, I will be able to check if the style is
bold.
Next j
Next i
Thanks.
The problem I have is that I format Word Table using Table in Excel and
would like to adjust to table depending of all cells format in excel.
So, I open the Excel workbook and copy a table value to word. I would like
to refer to Excel cells borders and text style (ex: bold) to be able to
adjust word table but doesn't know how ?
Dim appExcel As Object
Dim wbExcel As Object
Dim rngExcel as Range
Dim tbl As Word.Table
Dim DocWord1 As Word.Document
Dim strData as String
Set DocWord1 = AppWord.ActiveDocument
PathExcel = "table.xls"
Set appExcel = GetObject(, "Excel.Application")
Set tbl = DocWord1.Tables(2)
Set wbExcel = appExcel.Workbooks(PathExcel)
Set rngExcel = wbExcel.Sheets("table1.1").Range("Table1_1")
Set tbl = DocWord1.Tables(2)
DerLigneExcel = rngExcel.Rows.Count
DerLigneWord = tbl.Rows.Count
j = DerLigneExcel - DerLigneWord
For k = 1 To j
tbl.Rows.Add
Next k
For k = 1 To -j
tbl.Cell(5, 1).Select
Selection.SelectRow
Selection.Rows.Delete
Next k
With tbl
For i = 1 To tbl.Rows.Count
For j = 1 To tbl.Columns.Count
strData = rngExcel.Cells(i, j)
strData = Format(strData, "#,##0;(#,##0)")
.Cell(i, j).Range.Text = strData
'I would like to say:
' If rngExcel.Cells(i, j).Borders(x1EdgeTop).LineStyle = x1continue Then
' etc.
' End If 'Also, if this work, I will be able to check if the style is
bold.
Next j
Next i
Thanks.