|
楼主 |
发表于 2004-2-27 16:37
|
显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
楼上朋友回答的问题在no1贴我已修改,即做了回答 ===================================== 2、带指示进度的汇总宏及说明:
② 新建一个宏,代码为: Declare Function SHBrowseForFolder Lib "shell32.dll" Alias "SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) As Long Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As String) As Long Public Type BROWSEINFO hOwner As Long pidlRoot As Long pszDisplayName As String lpszTitle As String ulFlags As Long lpfn As Long lParam As Long iImage As Long End Type Sub main() Dim ph As String Dim fs, f, f1, fc, s, shtName, aa, ir, ic Dim i, StartRow, StopRow, NStartRow As Integer Dim myApp As New Application, wkSht As Worksheet
ph = BrowDir() If ph <> "" Then Application.ScreenUpdating = False Application.DisplayAlerts = False shtName = Application.InputBox("请按规范输入表格名称(5200405)") Worksheets.add.Name = shtName Set fs = CreateObject("Scripting.FileSystemObject") Set f = fs.GetFolder(ph) Set fc = f.Files i = 0 Guage.Show 0 If VBA.right(ph, 1) <> "\" Then ph = ph & "\" For Each f1 In fc If VBA.UCase(VBA.right(f1.Name, 3)) = "XLS" Then i = i + 1 CloseSame f1.Name Set wkSht = myApp.Workbooks.Open(ph & f1.Name).Sheets(1) If i = 1 Then wkSht.UsedRange.Select Else ir = wkSht.UsedRange.Rows.Count ic = wkSht.UsedRange.Columns.Count wkSht.UsedRange.Offset(1, 0).Resize(ir - 1, ic).Select End If wkSht.Application.Selection.Copy NStartRow = IIf(ActiveSheet.[F65536].End(xlUp).Row = 1, 1, ActiveSheet.[F65536].End(xlUp).Row + 1) ActiveSheet.Cells(NStartRow, 1).Select ActiveSheet.Paste Application.CutCopyMode = False wkSht.[a1].Copy myApp.Quit Set wkSht = Nothing Set myApp = Nothing End If Guage.Label2.Caption = Int((100 / f.Files.Count) * i) & "%" Guage.Label1.Width = 220 * i / f.Files.Count DoEvents Next ActiveSheet.UsedRange.Select Selection.Rows.AutoFit Selection.Columns.AutoFit Range("a2").Select Application.ScreenUpdating = True Application.DisplayAlerts = True Application.CutCopyMode = True If i > 0 Then MsgBox "月度计量汇总完成", vbInformation, "系统提示 End If Unload Guage Sheet3.AddItem End Sub Function BrowDir() As String Dim bi As BROWSEINFO Dim pidl&, rtn&, path$, pos%, mypath pidl& = SHBrowseForFolder(bi) path$ = VBA.space$(512) rtn& = SHGetPathFromIDList(ByVal pidl&, ByVal path$) If rtn& Then pos% = InStr(path$, VBA.chr$(0)) mypath = VBA.left(path$, pos - 1) End If BrowDir = mypath End Function Sub CloseSame(ss As String) Dim i For i = 1 To Application.Windows.Count If VBA.UCase(Application.Windows(i).Caption) = VBA.UCase(ss) Then Application.Windows(i).Close False Exit Sub End If Next i End Sub 这样一个带进度指示的汇总宏就完成了。
[此贴子已经被作者于2004-3-29 16:40:13编辑过] |
|