将Excel完全导入到工作簿中

时间:2019-05-28 20:11:41

标签: excel vba

我在这里找到了一个非常有用的现有代码,但是缺少一些东西。我想复制并粘贴工作簿中的所有内容,而无需定义范围。如何用全选替换此行?

targetSheet.Range("A1:H90").Value = sourceSheet.Range("A1:H90").Value

我尝试过:

targetsheet.range("A1").Currentregion.Copy 
sourcesheet.range("A1").Paste

没有用。

Public Sub Importfilev2() Dim customerBook As Workbook
Dim filter As String
Dim caption As String
Dim customerFilename As String
Dim customerWorkbook As Workbook
Dim targetWorkbook As Workbook

# make weak assumption that active workbook is the target
Set targetWorkbook = Application.ActiveWorkbook

# get the customer workbook
filter = "Text files (*.xlsx),*.xlsx"
caption = "Please Select an input file "
customerFilename = Application.GetOpenFilename(filter, , caption)

Set customerWorkbook = Application.Workbooks.Open(customerFilename)

# assume range is A1 - C10 in sheet1
# copy data from customer to target workbook
Dim targetSheet As Worksheet
Set targetSheet = targetWorkbook.Worksheets(1)
Dim sourceSheet As Worksheet
Set sourceSheet = customerWorkbook.Worksheets(1)

targetSheet.Range("A1:H90").Value = sourceSheet.Range("A1:H90").Value

# Close customer workbook
customerWorkbook.Close

0 个答案:

没有答案