[英]How to write VBA code to hide all the column and row headings in Excel?
Private Sub hideHeadings()
Dim obj As Window
For Each obj In Application.Windows
obj.DisplayHeadings = False
Next obj
End Sub
The above is my attempt, as when I recorded code to do it it goes ActiveWindow.DisplayHeadings = false. 以上是我的尝试,因为当我记录代码时,它会变为ActiveWindow.DisplayHeadings = false。 But I must be missing something.
但我必须遗漏一些东西。 Please help thanks in advance.
请提前帮助谢谢。
I think there is nothing you can do with that except iterating on each worksheet. 我认为除了在每个工作表上进行迭代之外,你无能为力。 I succeed with this code
我成功完成了这段代码
Private Sub hideHeadings()
Dim wrkbk As Workbook
Dim wrksh As Worksheet
Dim prev As Window
Set prev = ActiveWindow
For Each wrkbk In Workbooks
For Each wrksh In wrkbk.Worksheets
wrksh.Activate
ActiveWindow.DisplayHeadings = False
Next wrksh
Next wrkbk
prev.Activate
End Sub
Or in short: 或者简而言之:
Sub HideShowRowColumnHeaders()
ActiveWindow.DisplayHeadings = Not ActiveWindow.DisplayHeadings
End Sub
The code below toggles between hiding and showing the headings depending on what the their current status is. 下面的代码在隐藏和显示标题之间切换,具体取决于它们当前的状态。 It could be more useful as sometimes we don't want to hide or show the headings for all the sheets in the workbook but the one we are currently working with.
它可能更有用,因为有时我们不想隐藏或显示工作簿中所有工作表的标题,而是我们当前正在使用的工作表。
Sub HideShowRowColumnHeaders()
Dim StatusOfHeadings As Boolean
StatusOfHeadings = ActiveWindow.DisplayHeadings
If StatusOfHeadings Then
ActiveWindow.DisplayHeadings = False
Else
ActiveWindow.DisplayHeadings = True
End If
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.