Stray line after picture paste

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top