Run macro in protected worsheets

F

frankgtl

Hi

I have made some macros that among other things gets data from SQLserver
with QueryTables. And it works fine.

The problem is: The Worksheets should be protected, and I have tried to put
unprotect first in the code, and protect in the end of the code. Unprotect
works fine, but the protection takes effect too early, so I get the error
message: Can not write to protected cells.

I use .RefreshBackgroundQuery=True

Is there any way to say that all code should be executed (and finished)
before the next code line can start?

Frank
 
H

Homey

suggest you protekt sheet with userinterfaceonly set so macro can rite with
sheet prtected

Sheet1.Protect "pass", True, True, True, True
Range("A1").Value = "CanWriteEvenWithSheetLocked"

userinterfaceonly is 4th true above.

| Hi
|
| I have made some macros that among other things gets data from SQLserver
| with QueryTables. And it works fine.
|
| The problem is: The Worksheets should be protected, and I have tried to
put
| unprotect first in the code, and protect in the end of the code. Unprotect
| works fine, but the protection takes effect too early, so I get the error
| message: Can not write to protected cells.
|
| I use .RefreshBackgroundQuery=True
|
| Is there any way to say that all code should be executed (and finished)
| before the next code line can start?
|
| Frank
|
|
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top