文章预览
学习Excel技术,关注微信公众号: excelperfect 标签: VBA 要从关闭的工作簿中复制数据,有很多种方法,下面介绍最基本的一种方法。 假设要将一个工作簿中工作表 Sheet2 的单元格区域 A1:B50 的数据复制到当前工作簿的工作表 Sheet1 相应的单元格区域,可以使用下面的代码: Sub testCopyValueFromClosedWorkbook() Dim strFile As String Dim wbThis As Workbook Dim wksThis As Worksheet Dim wbThat As Workbook Dim wksThat As Worksheet Set wbThis = ThisWorkbook Set wksThis = wbThis.Sheets( "Sheet1" ) With Application.FileDialog(msoFileDialogFilePicker) If .Show = -1 Then strFile = .SelectedItems( 1 ) End If End With If strFile < > "" Then Set wbThat = Workbooks.Open(strFile) DoEvents Set wksThat = wbThat.Sheets( "Sheet2" ) wksThis.Range( "A1:B50" ).Value = wksThat.Range( "A1:B50" ).Value wbThat.Close False End If End Sub 代
………………………………