Excel 2016 VBA - 状态栏未显示完整消息

问题描述 投票:0回答:1

我最近在计算机上安装了Office 365的最新更新(Windows 10 64位)。从那时起,我注意到Excel 2016中有一件奇怪的事情:状态栏没有显示我在其上显示的完整自定义消息。当文件首次打开时它会显示它,但是一旦进行了更改,它就不会显示整个消息,而是显示最后几个字符所在的“...”。状态栏上还有足够的空间用于我的其余信息,所以我无法弄清楚为什么会发生这种情况。

我创建了一个新文件,看看它是否与我正在处理的特定工作簿有关。它也是在新文件上完成的,所以问题似乎与Excel本身有关。我在网上寻找解决方案,但无法找到任何东西。我甚至在其他几个论坛上发布了这个,但没有得到答案,所以我想在这里试试。 (请参阅我的帖子末尾有关其他论坛帖子的链接。)

以下是我的测试文件中发生的事情的摘要,以及文件本身的链接。

当我第一次打开我的测试文件时,它会显示状态栏消息。 StatusBarPic1

我做了这样,根据Cell A1中的值,显示的消息会发生变化。打开时,Cell A1为空。然后我将一个值放入其中,状态栏就像它应该有的那样改变了。 StatusBarPic2

然后我删除了单元格A1中的值,状态栏应该返回到与首次打开文件时一样的状态。但事实并非如此。它不会显示最后两个字符,而是显示“...”StatusBarPic3

有谁知道它为什么这样做?看起来奇怪的是,它会在首次打开工作簿时显示消息,但是一旦文件被使用,就不会显示完全相同的消息。

如果您想自己测试,下面是下载测试文件的链接。我很想知道它是否在其他版本的Excel上没有这样做。也许这是Excel 2016最近更新的新内容?

Test Excel file

最后,这里是我在其他论坛上发表的有关同一问题的帖子。 Link to post on Mr. Excel forums Link to post on VBA Express forums

编辑:根据请求,这是我已经放入我的测试文件的代码。

在Sheet1模块中:

Private Sub Worksheet_Change(ByVal Target As Range)

Application.StatusBar = MessageToDisplay

End Sub

在ThisWorkbook模块中:

Private Sub Workbook_Open()

Application.StatusBar = MessageToDisplay

End Sub

在Module1模块中:

Function MessageToDisplay() As String

Dim ValueCellA1 As String

ValueCellA1 = ThisWorkbook.Sheets("Sheet1").Range("A1").Value

MessageToDisplay = "This is a test to see how long of a message can be displayed on the status bar. I have noticed in Excel 2016 (most current version) that there seems to be a limit.  The value of Cell A1 is: " & ValueCellA1

End Function

在我正在处理的工作簿中,我似乎没有在我写入状态栏的字符串末尾有空格,但我仍然得到“...”而不是我的最后两个字符信息。

我逐步完成了代码并将带有消息的字符串放入监视窗口。接近代码的末尾,我拍了一下观察窗口的截图。这是字符串的最后一部分。 Watchlist image

然而,这是状态栏上显示的内容。 Status Bar image

在此特定工作簿中,用户通过选中某些框来决定在状态栏上显示哪些数据。以下是确定状态栏上实际显示内容的代码。在任何情况下,MessageToDisplay字符串都不应该在末尾有空格。

    If .Range("Options_StatusBar_ShowTotal1").Value = "YES" Then
        MessageToDisplay = "Total1: " & Total1
        FirstPartWritten = True
    End If

    If .Range("Options_StatusBar_ShowTotal2").Value = "YES" Then
        If FirstPartWritten = False Then
            MessageToDisplay = "Total2: " & Total2
            FirstPartWritten = True
        Else
            MessageToDisplay = MessageToDisplay & "     " & "Total2: " & Total2
        End If
    End If

    If .Range("Options_StatusBar_ShowTotal2Var").Value = "YES" Then
        If FirstPartWritten = False Then
            MessageToDisplay = "Total2 Var: " & Total2Var
            FirstPartWritten = True
        Else
            MessageToDisplay = MessageToDisplay & ", Var: " & Total2Var
        End If
    End If

    If .Range("Options_StatusBar_ShowTotal3").Value = "YES" Then
        If FirstPartWritten = False Then
            MessageToDisplay = "Total3: " & Total3
            FirstPartWritten = True
        Else
            MessageToDisplay = MessageToDisplay & "     Total3: " & Total3
        End If
    End If

    If .Range("Options_StatusBar_ShowTotal3Var").Value = "YES" Then
        If FirstPartWritten = False Then
            MessageToDisplay = "Total3 Var: " & Total3Var
            FirstPartWritten = True
        Else
            MessageToDisplay = MessageToDisplay & ", Var: " & Total3Var
        End If
    End If

此外,我试图显示的消息绝对不超过255个字符。

excel excel-vba statusbar
1个回答
1
投票

如果文本末尾有空格,上述行为似乎必须要做。我能够通过以下方式修复它

Function MessageToDisplay() As String

Dim ValueCellA1 As String

    ValueCellA1 = WorksheetFunction.Trim(ThisWorkbook.Sheets("Tabelle2").Range("A1").Value)
    If Len(ValueCellA1) = 0 Then
        MessageToDisplay = "This is a test to see how long of a message can be displayed on the status bar. I have noticed in Excel 2016 (most current version) that there seems to be a limit.  The value of Cell A1 is:"
    Else
        MessageToDisplay = "This is a test to see how long of a message can be displayed on the status bar. I have noticed in Excel 2016 (most current version) that there seems to be a limit.  The value of Cell A1 is: " & ValueCellA1
    End If

End Function

使用Application.StatusBar = "Test "时,我也显示了点。您似乎必须确保在要显示的文本末尾没有任何空白。

更新我认为状态栏的文本最大长度为255

© www.soinside.com 2019 - 2024. All rights reserved.