如何使用vba锁定excel单元格中的数据 [英] How to Lock the data in a cell in excel using vba

查看:110
本文介绍了如何使用vba锁定excel单元格中的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想阻止其他人使用 VBA 编辑我的 Excel 工作表中的单元格内容.可以这样做吗?

解决方案

您可以首先通过将单元格的锁定状态设置为 False 来选择您不想保护的单元格(用户可编辑):

>

Worksheets("Sheet1").Range("B2:C3").Locked = False

然后,您可以保护工作表,所有其他单元格都将受到保护.执行此操作并仍然允许您的 VBA 代码修改单元格的代码是:

Worksheets("Sheet1").Protect UserInterfaceOnly:=True

Call Worksheets("Sheet1").Protect(UserInterfaceOnly:=True)

I want to stop others from editing the cell contents in my excel sheet using VBA. Is it possible to do this?

解决方案

You can first choose which cells you don't want to be protected (to be user-editable) by setting the Locked status of them to False:

Worksheets("Sheet1").Range("B2:C3").Locked = False

Then, you can protect the sheet, and all the other cells will be protected. The code to do this, and still allow your VBA code to modify the cells is:

Worksheets("Sheet1").Protect UserInterfaceOnly:=True

or

Call Worksheets("Sheet1").Protect(UserInterfaceOnly:=True)

这篇关于如何使用vba锁定excel单元格中的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆