A
Alan
I am inserting an image into a Word table with the VBA code below that
runs in Excel. For some strange reason, I get a stray border line set
near the insertion. Is there any obvious way around this problem?
Alan
Sub InsertTable(WordApp As Object, startRow As Long, startCol As Long,
endRow As Long, endCol As Long, DrawBorder As Boolean)
Dim error As Boolean
error = False
If (startRow > 0) And (startRow <= endRow) Then
If CopyTable(WordApp, DataTableWS, ColumnLetter(startCol) &
startRow & ":" & ColumnLetter(endCol) & endRow) Then
Call FormatTable(WordApp, DrawBorder)
Else
error = True
End If
Else
error = True
End If
If error Then
Call DisplayError("CreateWordDocument", "Error", "Unable to
copy table")
End If
End Sub
Function CopyTable(WordApp As Object, WS As Worksheet, CopyRange As
String) As Boolean
CopyTable = False
On Error GoTo SafeExit
' Copy table from Excel
WS.Range(CopyRange).Copy
' Paste table into Word
With WordApp.Selection
.EndKey Unit:=wdStory
.TypeParagraph
.PasteExcelTable False, False, False
End With
CopyTable = True
Exit Function
SafeExit:
End Function
Sub FormatTable(WordApp As Object, DrawBorder As Boolean)
WordApp.Selection.Tables(1).Rows.Alignment = wdAlignRowCenter
If DrawBorder Then Call DrawTableBorders(WordApp)
End Sub
runs in Excel. For some strange reason, I get a stray border line set
near the insertion. Is there any obvious way around this problem?
Alan
Sub InsertTable(WordApp As Object, startRow As Long, startCol As Long,
endRow As Long, endCol As Long, DrawBorder As Boolean)
Dim error As Boolean
error = False
If (startRow > 0) And (startRow <= endRow) Then
If CopyTable(WordApp, DataTableWS, ColumnLetter(startCol) &
startRow & ":" & ColumnLetter(endCol) & endRow) Then
Call FormatTable(WordApp, DrawBorder)
Else
error = True
End If
Else
error = True
End If
If error Then
Call DisplayError("CreateWordDocument", "Error", "Unable to
copy table")
End If
End Sub
Function CopyTable(WordApp As Object, WS As Worksheet, CopyRange As
String) As Boolean
CopyTable = False
On Error GoTo SafeExit
' Copy table from Excel
WS.Range(CopyRange).Copy
' Paste table into Word
With WordApp.Selection
.EndKey Unit:=wdStory
.TypeParagraph
.PasteExcelTable False, False, False
End With
CopyTable = True
Exit Function
SafeExit:
End Function
Sub FormatTable(WordApp As Object, DrawBorder As Boolean)
WordApp.Selection.Tables(1).Rows.Alignment = wdAlignRowCenter
If DrawBorder Then Call DrawTableBorders(WordApp)
End Sub