简体   繁体   中英

Protect Logo in Excel sheet that is protected with VBA

Intro I have an Excel form that the cells highlighted blue in the attached screen-shot are protected via VBA, and the yellow cells are editable.

The reason I have a VBA protection is to allow deleting of entire row(s) while Column 5 and Column 7 are protected (and some other features which the Excel built in Sheet Protection feature doesn't not allow).

Challenge How do I protect the Logo with VBA, to disable the option of moving/resizing/deleting it.

I've looked in many of the experts forums before, but didn't a solution with VBA.

Thanks

在此处输入图像描述

If you look at the Worksheet.Protect method definition:
在此处输入图像描述
you will see that the second parameter (DrawingObjects) is the one you are after.

A quick example:

Sub DemoProtect()
    Dim mySheet As Worksheet: Set mySheet = ThisWorkbook.Worksheets(1)
    '
    mySheet.Protect Password:="test", DrawingObjects:=True, Contents:=True
End Sub

You can read the full help on Microsoft Docs: Worksheet.Protect method

You also need to keep in mind that a Shape can have the following "move" options:
在此处输入图像描述

The Locked checkbox must be on as well.

This is important because you might want to be able to resize the rows and columns by setting the AllowFormattingColumns and AllowFormattingRows parameters of the .Protect method so you need to decide if the shape moves and resizes with the range it sits on by setting one of the 3 options inside the Format Shape box.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM