当从excel和pasteSpecial复制范围到word时,我想在图片周围添加边框



我有两个问题。在word中,我可以进入书签"输入",但我想保留那个书签,并将我的选择粘贴到一个新书签中,比这个书签低一行。我试过选择。折叠方向:=wdCollapseEnd去结束,然后插入线,但这并不做的伎俩。也尝试了ActiveDocument.Bookmarks.Add "Excel1", newRange粘贴前(见注释部分的代码),但也没有运气。2当我复制一个范围从excel到word与DataType:=wdPasteEnhancedMetafile左边界是不可见的字(其他边界都很好。如何在粘贴元文件图片后添加左边框?

' in excel
selection.CopyPicture Appearance:=xlScreen, Format:=xlPicture
lWidth = selection.Width
lHeight = selection.Height
wdDoc.Activate
' With wdApp
''     Set prevRange = wrdDoc.Bookmarks("input").Range
'   Set newRange = prevRange   'Have to set the range to something initially
'   newRange.SetRange prevRange.End, prevRange.End
'   ActiveDocument.Bookmarks.Add "Excel1", newRange
'End With

With wdApp
.Visible = True
.selection.Goto What:=wdGoToBookmark, Name:="input"
.selection.Collapse Direction:=wdCollapseEnd
'leave the bookmark input as input and make a new bookmark on next word line for the picture.
.selection.InsertLine
.selection.PasteSpecial Link:=False, DisplayAsIcon:=False, _
DataType:=wdPasteEnhancedMetafile, Placement:=wdInline
'add a line at the left border of metafile ??
'.Selection.InsertAfter Chr(13)
.selection.InsertBreak (wdPageBreak)
End With
nextXL:

对于第一个问题,尝试这样做:

Sub Demo()
Dim xlSht As Excel.Worksheet
Dim wdApp As Word.Application, wdDoc As Word.Document, wdRng As Word.Range
Dim StrDocNm As String, StrBkMk As String
Set xlSht = ActiveSheet
StrBkMk = "BkMk1"
Set wdApp = GetObject(, "Word.Application")
With wdApp
'Point to the active document
Set wdDoc = .ActiveDocument
With wdDoc
'Paste the Excel data at the designated bookmark
If .Bookmarks.Exists(StrBkMk) Then
xlSht.Range("C2:E7").Copy
Set wdRng = .Bookmarks(StrBkMk).Range
wdRng.Characters.Last.Next.InsertBefore vbCr
wdRng.PasteSpecial Link:=False, DisplayAsIcon:=False, _
DataType:=wdPasteEnhancedMetafile, Placement:=wdInLine
.Bookmarks.Add StrBkMk, wdRng
xlSht.Range("C9:E15").Copy
With wdRng
.End = .End + 1
.Collapse wdCollapseEnd
.PasteSpecial Link:=False, DisplayAsIcon:=False, _
DataType:=wdPasteEnhancedMetafile, Placement:=wdInLine
.Bookmarks.Add "BkMk2", .Duplicate
End With
End If
End With
End With
Set wdRng = Nothing: Set wdDoc = Nothing: Set wdApp = Nothing: Set xlSht = Nothing
End Sub

请注意,不需要在Word或Excel中选择任何内容。还要注意,我没有包括任何打开文档的代码,等等。我想你已经排序好了。

对于第二个问题,边框似乎被应用到相邻单元格的右侧,而不是被复制单元格的左侧。我建议从源头上纠正。

最新更新