|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
zhaogang1960 发表于 2011-12-21 22:58
如果是打开工作簿需要密码,加上密码打开即可,如:
Set Wk = Workbooks.Open(MyPath & "\" & MyName, P ... - Sub combo()
- Dim Wk As Workbook, Sht As Worksheet, n As Integer, MyPath, MyName, t%
- t = Val(InputBox("请选择工作表序号", , 1))
- If t = 0 Then Exit Sub
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- For Each sh In Sheets
- If sh.Name <> ActiveSheet.Name Then sh.Delete
- Next
- n = 1
- MyPath = ThisWorkbook.Path & "" '指定路径
- MyName = Dir(MyPath & "" & "*.xls") '寻找第一项
- Do While MyName <> "" '开始循环
- If MyName <> ThisWorkbook.Name Then
- Set Wk = Workbooks.Open(MyPath & "" & MyName)
- Wk.Sheets(t).Copy after:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count) '此处只插个第一个sheet
- With ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count)
- .Name = Mid(MyName, 1, Len(MyName) - 4) '重新命名sheet
- .UsedRange.Value = .UsedRange.Value
- End With
- Wk.Close False
- End If
- MyName = Dir '查找下一个
- Loop
- Application.ScreenUpdating = True
- Application.DisplayAlerts = True
- End Sub
复制代码 麻烦大师再帮我修改一下代码,本人迫切需要这种合并功能,可太深奥了,能力有限,正在学习中。 |
|