VBA遍历文件夹内工作薄并指向指定工作表
我在遍历工作表时,当打开一个excel文件时,如果当前活动工作表不是sheet1,怎么样才激活sheet1。SubUnionWorksheets()Dimi,mAsInt...
我在遍历工作表时,当打开一个excel文件时,如果当前活动工作表不是sheet1,怎么样才激活sheet1。
Sub UnionWorksheets()
Dim i, m As Integer
Dim lj As String
Dim dirname As String
Dim nm As String
Dim Sht As Worksheet
Dim Str As String
lj = ActiveWorkbook.Path '查找工作簿
nm = ActiveWorkbook.Name
dirname = Dir(lj & "\*.xls")
m = 0
Do While dirname <> ""
If dirname <> nm Then
Workbooks.Open Filename:=lj & "\" & dirname '打开一个工作簿
Range("B10").Select
Sheet1.Activate '激活sheet1,但是无效
End If
dirname = Dir
Loop
end sub 展开
Sub UnionWorksheets()
Dim i, m As Integer
Dim lj As String
Dim dirname As String
Dim nm As String
Dim Sht As Worksheet
Dim Str As String
lj = ActiveWorkbook.Path '查找工作簿
nm = ActiveWorkbook.Name
dirname = Dir(lj & "\*.xls")
m = 0
Do While dirname <> ""
If dirname <> nm Then
Workbooks.Open Filename:=lj & "\" & dirname '打开一个工作簿
Range("B10").Select
Sheet1.Activate '激活sheet1,但是无效
End If
dirname = Dir
Loop
end sub 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询