【发布时间】:2014-05-27 02:43:10
【问题描述】:
我有一系列代码来跟踪文件路径并从多个excel文件中跟踪数据。
我想知道有什么方法可以修改代码,这样我就不需要通过更改单元格值来复制和粘贴相同的代码?
代码如下:
Sub FetchData()
Dim shDestin As Worksheet
Application.ScreenUpdating = False
Set shDestin = ThisWorkbook.Sheets("Sheet1")
CopyFileContent Range("B11").Value & shDestin.Range("A1").Value, _
shDestin, 11
CopyFileContent Range("B12").Value & shDestin.Range("A1").Value, _
shDestin, 12
CopyFileContent Range("B13").Value & shDestin.Range("A1").Value, _
shDestin, 13
CopyFileContent Range("B14").Value & shDestin.Range("A1").Value, _
shDestin, 14
CopyFileContent Range("B15").Value & shDestin.Range("A1").Value, _
shDestin, 15
CopyFileContent Range("B16").Value & shDestin.Range("A1").Value, _
shDestin, 16
CopyFileContent Range("B17").Value & shDestin.Range("A1").Value, _
shDestin, 17
CopyFileContent Range("B18").Value & shDestin.Range("A1").Value, _
shDestin, 18
CopyFileContent Range("B19").Value & shDestin.Range("A1").Value, _
shDestin, 19
有没有什么方法可以设置B11:B19 然后shDestin 11:19 之类的范围?
这会很麻烦,因为将来我可能在一个文件夹中有 50 多个文件来跟踪数据......
【问题讨论】:
标签: excel excel-2010 export-to-excel vba