今天项目上有个应用,获取指定Excel文件下的所有sheet的名称以及当前sheet中指定单元格的值,并把他们写到固定的sheet中去,看了下,文件比较多,而且每个文件sheet的个数比较多,也不一样,所以打算写个程序来帮我们实现任务,代码很简单,也写的比较死板。欢迎大家给出意见及你的代码:

Sub aaaa()
Dim sh1, sh2 As Worksheet
Dim shName, cellValue As String
'On Error Resume Next Set sh1 = Workbooks().Sheets()
'Workbooks.Open Filename:="D:\_jack\Finance Report\Report Layout\TA Opex Report 2014.xlsx"
Workbooks.Open Filename:="D:\_jack\Finance Report\Report Layout\Rolling PL Template v1 (2).xlsx" For i = To Workbooks().Worksheets.Count
Workbooks().Activate
Set sh2 = ActiveWorkbook.Worksheets(i)
sh2.Activate
n = sh2.Name
'v = sh2.Cells(5, 7).Value 'G5单元格
v = sh2.Cells(, ).Value 'C4单元格 Workbooks().Activate
sh1.Activate
sh1.Cells(i, ) = n
sh1.Cells(i, ) = v Next
Workbooks().Close
End Sub

版权:以上代码由本人开发,版权归 http://www.cnblogs.com/mq0036 个人所有。若用于非商业目的,您可以自由转载,转载请注明出处。

05-06 01:32