【问题标题】:Excel2013 can't write in the status bar?Excel2013不能在状态栏写字?
【发布时间】:2014-10-12 08:33:36
【问题描述】:

我想在 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 的方法状态栏中出错。它总是假的,我不知道为什么请任何想法或帮助。

【问题讨论】:

  • If UCase... 行前加一个msgbox Wb.Path 你看到了什么?
  • KekuSemau 当我从网上下载 EXCEL 文件时,msgbox Wb.Path 是空的,所以?????请帮忙
  • 基本上,代码似乎可以正常工作(但我这里没有 2013 年),目前我不能说更多。

标签: vba excel statusbar excel-2013


【解决方案1】:

试试这个:

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

【讨论】:

  • 嗨 ZAT,问题是我需要应用程序级事件来捕获任何工作簿的打开。因为当我使用 Private Sub Workbook_Open() 时,我找不到路径并且 vba 不知道活动工作簿
  • 不明白你的意思。您想感知任何工作簿的打开,并将您的代码放在工作簿的此工作簿下。对吗?
  • 我想为 excel 2013 创建一个 vba 宏。这个 vba 宏必须可用于所有 excel 文件,我在互联网上进行搜索,我发现我必须将代码放在 Excel 中添加-中,所以我尝试为excel的事件打开编写代码;当我在没有事件的情况下使用 workbook_Open 时,问题是当我打开 excel 文件时,vba 不知道活动的工作簿,因为它先打开加载项文件,然后是我的当前文件,所以我需要应用程序级事件。
  • 尝试在上面发布的代码中使用Activeworkbook.Path 代替ThisWorkbook.Path
  • 我试过 ZAT 但我有这个错误:运行时错误'91':对象变量或未设置块变量。同样的错误 activeworkbook 或 Thisworkbook,所以我使用了应用程序级事件,
【解决方案2】:

将 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

【讨论】:

    【解决方案3】:

    为什么不将宏放在个人工作簿中?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-05
      • 1970-01-01
      相关资源
      最近更新 更多