我想在Excel 2013的状态栏中写入Excel文档的开头,所以我在本工作簿中输入了以下代码:
Option Explicit
Private WithEvents app As Excel.Application
Private Sub app_WorkbookOpen(ByVal Wb As Workbook)
app.DisplayStatusBar = True
If UCase$(Wb.Path) = "C:\GED\TEMP" Then
app.StatusBar = "ok"
Else
app.StatusBar = "ko"
EndIF
End Sub
Private Sub Workbook_Open()
Set app = Application
End Sub
但是我总是在_Application的方法状态栏中出错。它总是假的我不知道为什么请任何想法或帮助。
答案 0 :(得分:0)
试试这个:
Private Sub Workbook_Open()
Dim wbPath,capPath
Application.DisplayStatusBar = True
wbPath = ActiveWorkbook.Path 'ThisWorkbook.Path
capPath = "C:\GED\TEMP"
If UCase$(wbPath) = capPath Then
Application.StatusBar = "Ok."
Else
Application.StatusBar = "ko."
End If
End If
答案 1 :(得分:0)
将sub重命名为app_Workbook_Open,同时注意" _" !
Option Explicit
Private WithEvents app As Excel.Application
Private Sub app_WorkbookOpen(ByVal Wb As Workbook)
with app
.DisplayStatusBar = True
If UCase(Wb.Path) = "C:\GED\TEMP" Then
.StatusBar = "ok"
Else
.StatusBar = "ko"
EndIF
end with
End Sub
Private Sub Workbook_Open()
Set app = Application
End Sub
答案 2 :(得分:0)
为什么不将宏放在个人工作簿中?