[英]VBA not updating on Protected Sheet — Excel Office 365
There are tons of questions already posted with a similar problem, but none of those solutions works for me. 已经发布了大量类似问题的问题,但是这些解决方案都不适合我。 I'm using Office 365, so maybe it's something that changed there.
我使用的是Office 365,所以也许它已经改变了。 Anyway, here is my issue.
无论如何,这是我的问题。
I have a file that pulls info from one main tab into other tabs. 我有一个文件,可将信息从一个主选项卡拉到其他选项卡。 On the subsequent tabs, I have VBA that auto-hides rows depending on the value that was pulled from the main tab.
在随后的选项卡上,我有VBA可以根据从主选项卡提取的值自动隐藏行。 Anytime the data in the main tab is updated, the subsequent tabs should also update.
每当主选项卡中的数据更新时,后续选项卡也应更新。 I had an issue with making this work, but I worked it out by using another cell to store the previous value that had transferred (comparing them, and running the code any time they were dissimilar).
我在进行这项工作时遇到了问题,但是我通过使用另一个单元格来存储已传输的先前值(比较它们,并在它们互不相同时运行代码)来解决。 The problem now is, of course, that it wont run when the tabs are protected.
现在的问题是,当然,当选项卡受到保护时,它将无法运行。 The tabs need to be protected to prevent end-users from corrupting the formulas and formatting, but I can't make it work with any of the solutions posted on StackOverflow.
需要保护这些选项卡,以防止最终用户破坏公式和格式,但是我不能使其与StackOverflow上发布的任何解决方案一起使用。 My code looks something like this:
我的代码如下所示:
Sub Worksheet_Calculate()
If Range("Old Value") <> Range("New Value").Value Then
Range("Old") = Range("New").Value
Rows.EntireRow.Hidden = False
<<Insert code to auto-hide based on "New Value" cell>>
End If
End Sub
I've tried adding Worksheet.Unprotect Password:=
and Worksheet.Protect Password:=
commands on either side of the If statement, and I get a 424 Object Required error. 我尝试在If语句的任何一侧添加
Worksheet.Unprotect Password:=
和Worksheet.Protect Password:=
命令,但出现424 Object Required错误。 I've tried using the "UserInterfaceOnly = True" command with my password protection, and it changes nothing (still get the trying to change a protected sheet error). 我尝试使用带有密码保护的“ UserInterfaceOnly = True”命令,但它什么也没有改变(仍然可以尝试更改受保护的工作表错误)。 I've tried creating another subroutine for unprotecting and re-protecting, then using a GoTo to run the original subroutine;
我尝试过创建另一个用于取消保护和重新保护的子例程,然后使用GoTo运行原始子例程。 but that didn't work either.
但这也不起作用。 I see a lot of solutions using ActiveSheet commands, but I don't think I can use them.
我看到了许多使用ActiveSheet命令的解决方案,但我认为我无法使用它们。 I'm updating the main tab, and the action is happening on another tab.
我正在更新主标签,并且该操作正在另一个标签上进行。 I'm fairly new to coding, and I'm teaching myself as I go;
我对编码还很陌生,并且我正在自学。 so, I could be missing something obvious.
因此,我可能会遗漏一些明显的东西。
It works perfectly when unprotected, so I guess I may have to just leave it that way. 在不受保护的情况下,它可以完美工作,所以我想我可能必须那样做。 I hate wasting time fixing the files when end-users do their best to ruin them, though, so I'd love to leave it protected.
但是,我讨厌在最终用户竭尽全力破坏文件时浪费时间修复文件,因此,我希望将其保护起来。
This may not be the final answer, but I seem to have stumbled upon a solution. 这可能不是最终答案,但我似乎偶然发现了一个解决方案。 Since the only thing I want happening on the protected sheet is for rows to auto-hide, I left row formatting unprotected.
由于我要在受保护的工作表上发生的唯一事情是使行自动隐藏,因此我没有保护行格式。 It seems to work fine that way.
这样看来效果很好。 You would think there's a way to run your VBA normally without having to jump through hoops because of protection....but, I'll take it for now.
您可能会认为有一种方法可以正常运行VBA,而无需出于保护而跳入箍圈……。但是,我现在就介绍一下。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.