从 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/