简体   繁体   中英

Excel 2013 protected sheet vba pop-up message

I'm working on a protected Excel workbook and am trying to eliminate or understand why the follow message occurs AFTER my .MsgBox popup:

The cell or chart you're trying to change is on a protected sheet. To make changes, click Unprotect Sheet in the Review tab (you might need a password).

I only have one input field in the workbook (date field), and I've set that cell style to "Input", as well as modified the cell format to "unprotected" so it stays editable even if the workbook is locked.

My VBA/Macro:

Sub WeeklyReport()

Dim Week As String

Set WeekValue = ThisWorkbook.Sheets("Report_Weekly").Range("PRM_weekvalue")

Week = WeekValue


Application.ScreenUpdating = False
Call unprotectmacro


With ActiveWorkbook.Connections("SQLDBConnection").OLEDBConnection
.CommandText = "EXEC dbo.usp_WeeklyReport '" & Week & "'"
ActiveWorkbook.Connections("SQLDBConnection").Refresh

    Sheets("Report_Weekly").Select
    Range("A13").Select
    MsgBox "The workbook is now refreshed."

End With
    ActiveSheet.Protect "passwordgoeshere", DrawingObjects:=True, Contents:=True, Scenarios:=True
    ActiveWorkbook.Protect "passwordgoeshere", Structure:=True, Windows:=False
    'Application.ScreenUpdating = True
End Sub

I would like this message not to appear to my end users, but I don't understand why it is occurring. My only thought is the table isn't done being refreshed after the protect sheet is turned back on. If that is the case, is there a way to wait for the background query to finish running before protecting the sheet again?

To resolve my issue, I went into the Data tab and unchecked "Enable background refresh". I believe this only resolves my issue because I am using an OLEDB connection type.

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