【发布时间】:2017-02-08 23:25:06
【问题描述】:
我正在用 word 编写一个命令按钮,它将多个 excel 电子表格中的命名范围复制并粘贴(作为图片)到同一个(打开的)word 文档中。在here的一些帮助下,我让它适用于单个excel文件,但是当我尝试修改多选代码时,它所做的只是多次粘贴相同的范围(即来自一个工作簿)。 此外,必须有一种比不断打开和关闭 excel 来复制范围更优雅(阅读:更快)的方式......
Private Sub CommandButton1_Click()
Dim objExcel As New Excel.Application, exWb As Workbook
With Application.FileDialog(msoFileDialogFilePicker)
.Title = "Select Risk Assessment Files"
.Filters.Add "Macro-Enabled Excel Files", "*.xlsm"
.AllowMultiSelect = True
If .Show <> -1 Then Exit Sub
For Each vrtSelectedItem In .SelectedItems
Set exWb = objExcel.Workbooks.Open(.SelectedItems(1))
'*** Use the values from excel here***
exWb.Sheets("Risk Assessment").Range("CRA").CopyPicture_
Appearance:=xlScreen, Format:=xlPicture
'*** Close the opened Excel file
exWb.Close Savechanges:=False
Set exWb = Nothing
Selection.EndKey Unit:=wdStory
Selection.Paste
Next vrtSelectedItem
End With
Selection.GoTo What:=wdGoToBookmark, Name:="insertbutton"
MsgBox ("Done")
End Sub
感谢您的帮助...
【问题讨论】: