2014-10-12 59 views
1

我想的Excel 2013狀態欄寫的,在文檔的Excel的開放,所以我必須在的ThisWorkbook puted下面的代碼:Excel2013無法在狀態欄中寫入?

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

把'msgbox Wb.Path'放在行'If UCase ...'之前......你看到了什麼? – KekuSemau 2014-10-12 13:39:11

+0

我看到「C:\ GED \ TEMP」 – 2014-10-12 13:57:50

+0

KekuSemau當我從互聯網下載EXCEL FILE時,msgbox Wb.Path爲空,所以?????請幫助 – 2014-10-12 15:33:00

回答

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 
+0

您好ZAT,問題是我需要應用程序級別的事件來捕獲任何工作簿的開放。因爲當我使用私人小組Workbook_Open(),我找不到路徑和vba不知道活動工作簿 – 2014-10-12 13:35:17

+0

不讓你的點。您想要感知任何工作簿的打開,並將您的代碼放在工作簿的本工作簿下。對? – ZAT 2014-10-12 14:09:40

+0

我想爲excel 2013創建一個vba宏。這個vba宏必須適用於所有的excel文件,我在互聯網上搜索,我發現我必須把代碼放在Excel加載項中,所以我試着做Excel的事件開放代碼;當我使用workbook_Open而沒有事件時,問題是當我打開excel文件時,vba不知道活動工作簿,因爲它首先打開加載項文件,然後打開當前文件,所以我需要應用程序級別的事件。 – 2014-10-12 14:23:07

0

子重命名爲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 
0

爲什麼不把宏放在個人工作簿中?