- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在创建一个自定义应用程序,它将在其自己单独的 Excel 实例(新应用程序)中启动。
新创建的实例默认不可见,因此需要手动使其可见。我喜欢仅在一切设置完毕后才让我的应用程序可见 - 以避免屏幕闪烁。我认为这是比关闭和打开 ScreenUpdating 更时尚的解决方案:即,如果应用程序无论如何都是不可见的,那么应该不需要切换 ScreenUpdating。在准备好之前,您可以将其保持不可见。
但是,我遇到了一些关于隐藏功能区的异常行为。以下命令:
Application.ExecuteExcel4Macro ("SHOW.TOOLBAR(" & Chr(34) & "Ribbon" & Chr(34) & ",False)")
...用于隐藏功能区。如果将命令简单地粘贴到“立即”窗口中,则可以看到其效果。它隐藏功能区:但应用程序窗口不受影响。但是...如果应用程序在执行此命令时不可见,则看起来不仅功能区被隐藏,而且窗口的整个标题栏也被隐藏!在以下子部分中对此进行测试:
Sub TestVisible()
Dim xl As Excel.Application
Set xl = New Excel.Application
xl.Workbooks.Add ' Required
' xl.Visible = True ' Un-comment out this line to preserve the Title bar
' If the following command is executed while Visible=False, then the TITLE bar will ALSO be hidden alongside the ribbon.
xl.ExecuteExcel4Macro ("SHOW.TOOLBAR(" & Chr(34) & "Ribbon" & Chr(34) & ",False)") ' Hide the ribbon
xl.Visible = True
End Sub
所以我的问题是:有人对这种行为有解释吗?这是一个错误吗?如果有,是否为人所知?如果不是,那么有解决办法吗? (除了在隐藏功能区之前简单地使应用程序可见,然后在需要时设置 ScreenUpdating 的解决方法之外。)
最佳答案
我在这方面花费的时间比我应该花的时间多:)但这里有一些解决方法,也是我认为的完整解决方案,因为它将“标题”栏恢复到新的 Excel 实例。
我可以推测“为什么”ExecuteExcel4Macro
在这里不能正常工作:
ExecuteExcel4Macro
实际上是一个可以追溯到 1995 年之前的 Excel 的遗留问题。它不经常使用,而且我认为其中很多功能不再起作用。使用它来隐藏功能区菜单栏——该菜单栏直到 2007 年才存在,它代表了对完全暴露于 VBA 的遗留 Application.CommandBars
的范式转变(例如:您无法像在 Excel <= 2003 中那样执行 Application.CommandBars("some command bar name").Visible = False
) - 似乎可能存在一些 Microsoft 可能永远不会出现的错误地址。
通过使用各种 WinAPI 函数进行进一步调查,我发现一个有趣的事情是,当 Excel 不可见时,FindWindow
函数返回 0。我可能做错了什么,但如果没有,那么我猜测这在某种程度上导致了您观察到的行为。
这是一种类似的方法,但功能区只是最小化,用户仍然可以切换:
Sub TestAlternate()
Dim xl As Excel.Application
Set xl = New Excel.Application
xl.Workbooks.Add ' Required
xl.Application.CommandBars.ExecuteMso ("HideRibbon")
xl.Visible = True
End Sub
调整原始代码的另一个可能的解决方法是强制新实例最小化(并且可见),以避免标题栏出现错误行为:
Sub TestVisible()
Dim xl As Excel.Application
Set xl = New Excel.Application
xl.Workbooks.Add ' Required
xl.Application.WindowState = xlMinimized
xl.Visible = True ' Un-comment out this line to preserve the Title bar
' If the following command is executed while Visible=False, then the TITLE bar will ALSO be hidden alongside the ribbon.
xl.ExecuteExcel4Macro ("SHOW.TOOLBAR(" & Chr(34) & "Ribbon" & Chr(34) & ",False)") ' Hide the ribbon
xl.Visible = False
xl.Application.WindowState = xlNormal
' any additional code required to set up/configure the new instance/application
xl.Visible = True
End Sub
第三种可能的解决方案如OP评论中提到的,我建议重构代码以从模板添加新工作簿。该模板将包含 CustomUI XML 规范和适当的 VBA 回调函数来隐藏功能区上的项目。我不能 100% 确定您可以使用此方法完全复制您的设计意图,对于初学者来说这不是一件小事,但它可能值得探索。
<小时/>我找到了this solution这很有希望,但实现比我预期的要复杂,但我认为我有一些适合您的目的的东西,是根据上述内容进行修改的。
在我所做的调试中,功能区和标题栏似乎紧密地联系在一起,您会注意到我根本不使用 ExecuteExcel4Macro
,因为此函数调用需要还要照顾丝带。我怀疑这个链接可能会导致您原来的问题!
以下是 API Hook :
Option Explicit
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
(ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" _
(ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Const GWL_STYLE = (-16)
Private Const WS_CAPTION = &HC00000
Private Const WS_MAXIMIZEBOX = &H10000
Private Const WS_MINIMIZEBOX = &H20000
Private Const WS_SYSMENU = &H80000
Private Declare Function SetWindowPos Lib "user32" _
(ByVal hwnd As Long, ByVal hWndInsertAfter As Long, _
ByVal x As Long, ByVal y As Long, ByVal cx As Long, _
ByVal cy As Long, ByVal wFlags As Long) As Long
Private Enum ESetWindowPosStyles
SWP_SHOWWINDOW = &H40
SWP_HIDEWINDOW = &H80
SWP_FRAMECHANGED = &H20
SWP_NOACTIVATE = &H10
SWP_NOCOPYBITS = &H100
SWP_NOMOVE = &H2
SWP_NOOWNERZORDER = &H200
SWP_NOREDRAW = &H8
SWP_NOREPOSITION = SWP_NOOWNERZORDER
SWP_NOSIZE = &H1
SWP_NOZORDER = &H4
SWP_DRAWFRAME = SWP_FRAMECHANGED
HWND_NOTOPMOST = -2
End Enum
Private Declare Function GetWindowRect Lib "user32" _
(ByVal hwnd As Long, lpRect As RECT) As Long
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Sub ShowTitleBar(xlApp As Excel.Application, bShow As Boolean, Optional bCaptionOverride As Boolean = True)
Dim lStyle As Long
Dim tRect As RECT
'Dim sWndTitle As String
Dim xlhnd
'## I modified this function to receive an Application instance and
'## to use it's .Hwnd property rather than the FindWindow API call
xlhnd = xlApp.hwnd
'// Get the window's position:
GetWindowRect xlhnd, tRect
If Not bShow Then
lStyle = GetWindowLong(xlhnd, GWL_STYLE)
lStyle = lStyle And Not WS_SYSMENU
lStyle = lStyle And Not WS_MAXIMIZEBOX
lStyle = lStyle And Not WS_MINIMIZEBOX
'## I added this logic to ensure the CAPTION may always displayed if bCaptionOverride
If Not bCaptionOverride Then
lStyle = lStyle And Not WS_CAPTION
Else
lStyle = lStyle Or WS_CAPTION
End If
Else
lStyle = GetWindowLong(xlhnd, GWL_STYLE)
lStyle = lStyle Or WS_SYSMENU
lStyle = lStyle Or WS_MAXIMIZEBOX
lStyle = lStyle Or WS_MINIMIZEBOX
lStyle = lStyle Or WS_CAPTION
End If
SetWindowLong xlhnd, GWL_STYLE, lStyle
xlApp.DisplayFullScreen = Not bShow
'// Ensure the style is set and makes the xlwindow the
'// same size, regardless of the title bar.
SetWindowPos xlhnd, 0, tRect.Left, tRect.Top, tRect.Right - tRect.Left, _
tRect.Bottom - tRect.Top, SWP_NOREPOSITION Or SWP_NOZORDER Or SWP_FRAMECHANGED
End Sub
这是我们用于隐藏功能区的新子项,已在 Excel 2016 中进行了测试:
Sub Test()
Dim xl As New Excel.Application
xl.Workbooks.Add
ShowTitleBar xl, False
' configure the application
xl.Visible = True
' Re-enable the ribbon, or the user can double-click the title bar or Restore menu.
ShowTitleBar xl, True
End Sub
我在 Visible = True
语句后中断并确认功能区未显示:
最后,在过程结束时我们可以恢复功能区(如果需要)
<小时/>注意:我注意到菜单中的“恢复”选项(右键单击标题栏中的 Excel 图标)不会恢复功能区,如果您使用 ExecuteExcel4Macro
,但如果您使用 WinAPI 调用,它确实会恢复功能区。
如果您只是设置一个环境,那么这应该不重要,但我实现的方法并不能完全复制该功能。可以通过 WinAPI 进一步配置(例如,我知道您可以使用 lStyle = lStyle And Not WS_SYSMENU
关于Excel异常行为: hiding ribbon also hides TITLE bar if application is invisible,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51672541/
我已经实现了不可见的 reCAPTCHA,一切正常,但谷歌以他们的智慧添加了一个条款/隐私框作为屏幕右下角的覆盖: 不幸的是,因为我已经有一个时间表框,所以它看起来很乱。 Google 和我的调度程序
有点直截了当:当 asp:Validators 在不可见的容器中时,它们是否仍会执行验证?如果他们的 ControlToValidate 目标是不可见的呢? 例如: 上面是不可
我是 Android 开发的新手,所以我正在开发一个简单的应用程序来隐藏按下某个按钮的 TextView ,因此在按钮的 OnClick 事件方法的 java 代码中我将 TextView 设置为不可
?invisible说 Return a (temporarily) invisible copy of an object. 那个括号暗示隐形不会永远持续下去,但我找不到任何可以解释它何时消失的东西
根据 Lighthouse 的测量,包含 Google 的“隐形验证码”似乎大大增加了“首次交互”(以及随后的“持续交互”)时间。 我使用 HTML5 样板模板设置了两个空网页。这些站点的不同之处仅在
我有一个不可见的 recaptcha,它可以工作,但对所有用户来说都是完全可见的。我的意思是: 我的控制台说: Uncaught Error: Missing required parameters:
我正在编写简单的 APN 切换应用程序。我想问一下如何强制android不显示任何窗口。目前在运行我的应用程序后,会短暂显示带有应用程序名称的黑屏,然后消失。是否可以不显示任何内容(仅显示 Toast
在我的应用程序中,我有一些控件,例如 NSButton 和 NSTextfield,我想将其隐藏。我知道我可以在 Interface Builder 中做到这一点,但我需要在代码中做到这一点。 我仍然
我想从所有市场上删除“待售” ios应用程序,因此不再可以购买,但仍可以为现有用户提供更新。这可能吗? 马丁 最佳答案 不,如果您要提供更新,则任何人都必须可以下载/购买。 恐怕是标准的苹果程序。苹果
这个问题已经有答案了: Eclipse pausing without a breakpoint (6 个回答) 已关闭 8 年前。 我正在使用 Eclipse Juno。当我调试桌面应用程序时,调试
我在 FMX 上有一个 TGrid,有 3 列,第二列是 Visible False,如果我单击第一列并按箭头聚焦于下一个可见列,光标不会转到第三列,它会消失,就像聚焦在第二列上一样,如果我再次按下箭
这是我的进度对话框 progressBar = new ProgressDialog(Wallpapers.this); progressBar.setCancelable(false); progr
我正在尝试从使用 Google reCaptcha v2 迁移到不可见的 reCaptcha。我使用 Parsley.js 进行表单验证,并使用 Malsup Ajax 表单插件提交表单。我当前的代码
而不是使用: if ( ! $('#XX').is(':visible) ) 是否有一个名为 invisible 的值?我试过了,但不起作用。 谢谢! 最佳答案 ':hidden' if ($('#X
这些是 “程序员可见” x86-64 寄存器: (来源:usenix.org) 隐形寄存器呢?刚刚才知道MMU寄存器,Interrupt Descriptor Table(IDT)使用了这些不可见的寄
我正在创建一个类库,里面有不同的功能。我还有一个控制台应用程序,一旦它们引用类库就可以访问这些函数。我想知道如何使一个函数“不可见”,这样客户就看不到它的存在,只有在他们完美地写出来的情况下他们才能使
我需要您的帮助,从图形类生成屏幕外图像并将其转换为二进制数据,而不将它们设置在屏幕上可见。我想生成大量标签并将它们作为二进制数据发送到打印机。如果我创建图像,在屏幕上显示它然后发送它,一切都很好,但是
假设我有以下代码: //myjs.js let testingVisibility = "hello"; 当我想通过 Firefox 中的控制台访问 testingVisibility 变量时,未声
在 Swift 中,我可以创建一个 String 变量,如下所示: let s = "Hello\nMy name is Jack!" 如果我使用 s,输出将是: Hello My name is J
我必须编写一些 javascript 代码来截取网页的屏幕截图,但不能在前台渲染它。首先,这可能吗?我需要使用一些外部库吗?请给我一些想法:) 最佳答案 如果您正在谈论在 Firefox chrome
我是一名优秀的程序员,十分优秀!