vba - 在 Excel 2013 中隐藏非事件工作表中的行

标签 vba excel excel-2013

从 Excel 2010 切换到 Excel 2013,

当 Sheet2 处于非事件状态时

代码

Worksheets("Sheet2").Rows("432:432").EntireRow.Hidden = False

给出错误

Unable to set the Hidden property of the Range class

但是当 Sheet2 是事件工作表时工作正常

在 Excel 2010 中,VBA 在隐藏 InactiveSheets 中的行没有问题。

这是 Excel 2013 中的更改吗?如果是,请修复。

编辑: Worksheets("Sheet2").Protect 密码:="password", userinterfaceonly:=True Worksheets("Sheet2").Rows("2:2").EntireRow.Hidden = False 将 userinterfaceonly 选项设置为 true 时,隐藏行的 VBA 代码仅在工作表处于事件状态时才起作用

我无法在新的 2013 工作表上重现此错误。但仅限于 2013 年打开 2010 Excel 应用程序时。不知道我是否在此处使用任何设置。

最佳答案

Sub MakeScript1()
application.ScreenUpdating = False
Sheets("Script1").Visible = True
ThisWorkbook.Sheets("Script1").Select
  Dim x As Long, Z As Long, FF As Long, TextOut As String
  Const OutputPath As String = "c:\temp\"   '<==Note the trailing backslash
  Const BaseFileName As String = "Script1"
  Const StartColumn As Long = 1   'Assumed Column A
  Const StartRow As Long = 1      'Assumed Row 1
  For x = StartColumn + 1 To StartColumn + 1
    TextOut = ""
    For Z = StartRow To StartRow + 19
      TextOut = TextOut & Cells(Z, StartColumn).Value & " " & Cells(Z, x).Value & vbNewLine
    Next
    FF = FreeFile
    Open OutputPath & BaseFileName & ".vbs" For Output As #FF
    Print #FF, TextOut
    Close #FF
  Next
ThisWorkbook.Sheets("Instructions").Select
Sheets("Script1").Visible = False
application.ScreenUpdating = True
End Sub

看看我是怎么做的

Sheets("Script1").Visible = True

然后

Sheets("Script1").Visible = False

关于vba - 在 Excel 2013 中隐藏非事件工作表中的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23554035/

相关文章:

excel - VBA 求解器编译错误 : Sub or Function not defined

excel - 如何对适用条件的过滤行求和?

excel - 满足一定条件的单元格字符串的总和

sql-server - 请注意,文档的某些部分可能包含文档检查器无法删除的个人信息

vba - 如何处理 Workbook.SaveAs 覆盖确认上的 'No' 或 'Cancel'?

excel - 将文件从多个文件夹移动到单个文件夹

regex - 如何用@ 替换 'at'

excel - 如何在不打开工作簿的情况下检查表格是否存在于关闭的工作簿中的工作表中

ruby - 如何关闭 ruby​​ gem "Spreadsheet?"中的文件

excel - 如何在单元格中添加过滤和排序按钮?