Excel vba EntireRow.AutoFit 不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22695928/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-12 02:32:40  来源:igfitidea点击:

Excel vba EntireRow.AutoFit does not work

excel-vbavbaexcel

提问by Max

i have the following code in an add-in, which is called from the ribbon. It is meant to make all lines visible from the current line to the next visible line. The lines are hidden by an autofilter.

我在一个加载项中有以下代码,它是从功能区调用的。它旨在使从当前行到下一个可见行的所有行都可见。这些行被自动过滤器隐藏。

Sub Details4(control As IRibbonControl)
ActiveSheet.Unprotect Password:="xxx"
    SendKeys "+{DOWN}+ ", True
    ActiveCell.Rows("1:" & Selection.Rows.Count).EntireRow.EntireRow.AutoFit
End Sub

It does mark the lines as i wanted it to do, but the auto-fit does not work. When I double-click the line-height (which should do the same as the autp-fit) alle lines are visible as I wished this do to.

它确实按照我的意愿标记了线条,但自动调整不起作用。当我双击 line-height(它应该与 autp-fit 一样)时,等位线就像我希望的那样可见。

Can anyone see a problem? I know "sendkey" is not the best Thing in programming, but I had no other easy idea how to mark the range up to the next visible line...

任何人都可以看到问题吗?我知道“sendkey”不是编程中最好的东西,但我没有其他简单的想法如何将范围标记到下一个可见行......

Thanks max

谢谢最大

采纳答案by Max

solved this by changing the code to:

通过将代码更改为:

For Each Row In ActiveCell.Rows("1:" & Selection.Rows.Count)
    Row.EntireRow.AutoFit
Next

and deleting the line

并删除该行

ActiveCell.Rows("1:" & Selection.Rows.Count).EntireRow.EntireRow.AutoFit

of course...

当然...

回答by Alan Waage

You have an extra .EntireRow call.

您有一个额外的 .EntireRow 调用。

   Rows("9:13").EntireRow.autofit

Works just fine.

工作得很好。

For your sendkey issue, try something like this:

对于您的 sendkey 问题,请尝试以下操作:

   Range(Selection, Selection.End(xlDown)).Select