我正试图整合一个状态栏进度表'在加载冗长的宏时帮助用户。
我进行了一些研究,发现this是我想要使用的类型。
我遇到的问题是进度条没有移动到状态栏以及第一个和最后一个消息,即" Working"和"提取的所有文件"没有显示。我哪里出错?
Private Sub btnFetchFiles_Click()
Dim j As Integer
iRow = 20
fPath = "\\c\s\CAF1\Dragon Mentor Group\Dragon Scripts\Current\April 2015"
If fPath <> "" Then
' make StatusBar visible
Application.DisplayStatusBar = True
Set FSO = New Scripting.FileSystemObject
'First Message
Application.StatusBar = String(5, ChrW(9609)) & " Working..."
If FSO.FolderExists(fPath) <> False Then
'Second Message
Application.StatusBar = String(5, ChrW(9609)) & " Working..."
Set SourceFolder = FSO.GetFolder(fPath)
'Third Message
Application.StatusBar = String(5, ChrW(9609)) & " Working..."
IsSubFolder = True
'Fourth Message
Application.StatusBar = String(5, ChrW(9609)) & " Still Working..."
Call DeleteRows
If AllFilesCheckBox.Value = True Then
'Fifth Message
Application.StatusBar = String(5, ChrW(9609)) & " Still Working..."
Call ListFilesInFolder(SourceFolder, IsSubFolder)
Call ResultSorting(xlAscending, "C20")
Call FormatCells
Else
Call ListFilesInFolderXtn(SourceFolder, IsSubFolder)
Call ResultSorting(xlAscending, "C20")
Call FormatCells
End If
'Sixth Message
Application.StatusBar = String(5, ChrW(9609)) & "Still Working..."
lblFCount.Caption = iRow - 20
'Seventh Message
Application.StatusBar = String(5, ChrW(9609)) & "Almost Done..."
Else
MsgBox "Selected Path Does Not Exist !!" & vbNewLine & vbNewLine & "Select Correct One and Try Again !!"
End If
Else
MsgBox "Folder Path Can not be Empty !!" & vbNewLine & vbNewLine & ""
End If
'Eigth Message
Application.StatusBar = String(5, ChrW(9609)) & "All Files Extracted..."
'Relinquish the StatusBar
Application.StatusBar = False
End Sub
答案 0 :(得分:1)
您没有看到它们的原因是它们会被下一条StatusBar
消息立即覆盖。
以此为例:
'Eigth Message
Application.StatusBar = String(5, ChrW(9609)) & "All Files Extracted..."
'After the previous message has displayed for zero seconds,
'Relinquish the StatusBar
Application.StatusBar = False
您正在显示一条消息并立即将其删除。
您的第一条消息也是如此。介于两者之间的语句可能在不到一毫秒的时间内执行,因此您的第一条消息将显示多长时间;因此你不会看到它。在某种程度上,这是完全有道理的,因为如果进展是即时的,则不需要显示进度表。
link you provide中的示例使用Application.Wait
语句强制程序在显示进度时等待。但这只是为了说明目的;你永远不会故意放慢你的实际计划。
进度条不会变得越来越长的原因是您明确告诉它保持相同的长度:
String(5, ChrW(9609))
将始终返回一个长度为五个字符的进度条:▉▉▉▉▉
。 link you provide中的示例使其从5增长到10到15.