Excel 2010命令button消失

我正在开发Excel 2010工作簿,处于手动公式计算模式。

(文件 – >选项 – >公式 – >工作簿计算 – >手动)

我在工作表(ActiveX控件)中有一些命令button,并将它们设置为使用单元格移动和resize(右键单击button – >格式控件 – >属性 – >使用文本移动和resize)。 这是因为我在某些条件下过滤了一些行,并且我希望放置在这些行中的button根据其托pipe行的显示模式出现和消失。 这一切都很好,直到我保存他的工作表时,一些行(因此button)被过滤掉(即不显示)。 当我再次打开文件,并展开过滤的行,button不显示。 当检查他们的属性,我看到他们的'可见'属性是'真',但他们的高度是0,并且这不会改变当我过滤他们的主机行。 我想再次强调的是,在保存文件之前 – 过滤和取消过滤button效果很好。

非常感谢这里的任何帮助。

谢谢。

马坦。

好的,所以我得到与ActiveX或表单控件相同的结果。 无论出于何种原因,控制器的原始高度似乎不会超越保存和closures。

另一个select是简单地清除工作簿的CloseSave事件上的自动筛选。 但是,如果您希望在保存并重新打开文件时保留一些filter,则可能不是您想要的。 将filter参数保存在隐藏表格中,或直接操作VBE / VBA,可能是可能的,但是这似乎是一个比它更值钱的麻烦。 然后,当您重新打开工作簿时,您可以重新应用筛选器。

这是我build议的代码

注:我依靠工作表的_Calculate事件与一个隐藏的CountA公式(设置,更改,或清除AutoFilter将触发此事件)。 我把公式放在E1中,这样你就可以看到它的样子了:

在这里输入图像说明

由于您的应用程序依赖于Calculation = xlManual因此这种方法无法完全适用于您,但在任何情况下,子例程UpdateButtons都可以重新使用。 您需要根据需要将其绑定到应用程序中的其他事件或function。

这是代码

 Option Explicit Private Sub UpdateButtons() '## Assumes one button/shape in each row ' buttons are named/indexed correctly and ' the first button appears in A2 Dim rng As Range Dim shp As Shape Dim i As Long Application.EnableEvents = False '## use this to define the range of your filtered table Set rng = Range("A1:A6") '## Iterate the cells, I figure maybe do this backwards but not sure ' if that would really make a difference. For i = rng.Rows.Count To 2 Step -1 Set shp = Nothing On Error Resume Next Set shp = Me.Shapes(i - 1) On Error GoTo 0 If Not shp Is Nothing Then DisplayButton Me.Shapes(i - 1), Range("A" & i) End If Next Application.EnableEvents = True End Sub Private Sub DisplayButton(shp As Shape, r As Range) '# This subroutine manipulates the shape's size & location shp.Top = r.Top shp.TopLeftCell = r.Address shp.Height = r.Height End Sub Private Sub Worksheet_Change(ByVal Target As Range) MsgBox "_Change" End Sub Private Sub Worksheet_SelectionChange(ByVal Target As Range) ''## Assumes one button/shape in each row '' buttons are named/indexed correctly and '' the first button appears in A2 'Dim rng As Range 'Dim shp As Shape 'Dim i As Long ' ''## Uncomment this line if you want an annoying message every time ''MsgBox "Refreshing Command Buttons!" ' 'Application.EnableEvents = False ''## use this to define the range of your filtered table 'Set rng = Range("A1:A6") ' ''## Iterate the cells, I figure maybe do this backwards but not sure '' if that would really make a difference. 'For i = rng.Rows.Count To 2 Step -1 ' Set shp = Nothing ' On Error Resume Next ' Set shp = Me.Shapes(i - 1) ' On Error GoTo 0 ' ' If Not shp Is Nothing Then ' DisplayButton Me.Shapes(i - 1), Range("A" & i) ' End If 'Next ' 'Application.EnableEvents = True End Sub 

另一种select请参阅这篇文章 。 您可以使用RibbonXML自定义重新使用现有的命令。 虽然本文面向C#和Visual Studio,但可以使用CustomUI编辑器来完成。

我有一个类似的问题,当删除filter时,button消失(在左上angular移动)。

我find的解决scheme是在列标题上方添加一行,以便button仍然出现在列的顶部,但未触及放置filter的行。

添加/删除filter会停止干扰button的位置。

我有一个类似的问题,表单button似乎工作正常,但然后保存并重新打开工作簿后消失。 具体来说,这发生在表单button所在的部分隐藏行(使用vba代码完成)。

看起来像一个真正的bug,但我不知道链接在哪里。

通过将表单button更改为ActiveXbutton,button停止消失,但在行被隐藏时开始移动/聚束到屏幕的顶部。 我只是添加了一些VBA来重新定位button(例如CommandButton1.Top =范围(A12:A12)。顶部 – >将ActiveX命令button移动到第12行)。