简体   繁体   English

如何编写VBA代码以隐藏Excel中的所有列和行标题?

[英]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.

相关问题 如何编写VBA代码以隐藏Excel中的某些单元格 - how to write VBA code to hide some cells in excel 如何编写代码VBA以在一张Excel中复制所有图纸 - How to write code VBA for copying all sheets in one sheet excel Excel VBA - 向下查看 A 列以获取特定值并隐藏活动单元格行下方的所有行? - Excel VBA - Look down column A for specific value and hide all rows below activecell row? Excel VBA代码,用于在列中将所有“。”替换为“,” - Excel VBA code for replacing all “.” by “,” in a column 有没有办法在不使用VBA的情况下隐藏excel中的行或列? - Is there a way to hide a row or column in excel without using VBA? 如果VBA for Excel中单元格区域中的所有可见单元格都为空白,如何隐藏行? - How to hide row if all visible cells in cell range are blank in VBA for Excel? Excel VBA-查找匹配的列标题并删除该列 - Excel VBA - Find matching column headings and delete the column 如果工作簿中所有工作表的值都大于1,则Excel中要删除A:A列中的行的VBA代码是什么? - What is the VBA code in Excel to Delete row(s) in column A:A if value is greater than 1 for all sheets in workbook Excel VBA:如何在其中用“ @”写商业名称的列名 - Excel VBA: How to write column name with commercial at “@” in it 如何在 excel VBA 中编写毕达哥拉斯公式,就像我需要 select 列 A 和列 B 的所有值 - How to write Pythagoras formula in excel VBA, like I need to select all the values of column A and column B
相关标签
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM