Refresh Query su Foglio protetto
Hai un problema con Excel? 
Refresh Query su Foglio protetto
di Ackos (utente non iscritto) data: 14/07/2014 18:42:03
Salve a tutti,
sono di fronte al seguente problema.
Ho un file excel abbastanza corposo che vorrei proteggere in toto dando la possibilità agli utenti di modificare solo alcune celle di alcuni fogli.
Molti fogli fungono da database e vorrei tenerli nascosti; due di questi sono alimentati da query esterne che ho implementato tramite microsoft query.
Andando con ordine:
1)con "Enable_me()", in un colpo solo blocco tutti i fogli e do la possibilità agli utenti di usare filtri, pivot e aprire e/o nascondere colonne compattate.
2)con "Refresh()", vorrei sbloccare tutti i fogli, eseguire le query ("UpdateQuote") e aggiornare i dati nelle pivot, e infine ribloccarli.
Purtroppo, qualcosa non funziona quando lancio Refresh: sono sicuro la richiesta di update delle query venga eseguito visto che il collegamento viene stabilito ma, alla fine di tutto, mi escono due errori che mi dicono che i fogli interessati sono protetti da password e quindi non è possibile editarli. In sostanza i dati che mi interessano vengono effettivamente recuperati ma non è possibile trasferirli e sovrascriverli nei fogli.
Qualcuno può darmi una mano?
Grazie mille in anticipo
Sub Enable_Me()
Dim wSheet As Worksheet
Dim Pwd As String
With Application
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With
Application.DisplayAlerts = False
On Error Resume Next
For Each wSheet In Worksheets
wSheet.Protect "PASSWORD", userinterfaceonly:=True
wSheet.EnableOutlining = True
wSheet.EnableAutoFilter = True
wSheet.EnablePivotTable = True
Next wSheet
If Err = 0 Then
MsgBox "MESSAGGIO MINATORIO", vbExclamation, "Grazie"
End If
On Error GoTo 0
Application.DisplayAlerts = True
With Application
.Calculation = xlCalculationAutomatic
.ScreenUpdating = True
End With
End Sub
-----------------------------------------
Sub refresh()
unLock
UpdateQuote
ActiveWorkbook.RefreshAll
Lock
End Sub
-----------------------------------------------
Private Sub Lock()
Dim wSheet As Worksheet
Dim Pwd As String
With Application
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With
Application.DisplayAlerts = False
On Error Resume Next
For Each wSheet In Worksheets
wSheet.Protect "def34t", userinterfaceonly:=True
wSheet.EnableOutlining = True
wSheet.EnableAutoFilter = True
wSheet.EnablePivotTable = True
Next wSheet
On Error GoTo 0
Application.DisplayAlerts = True
With Application
.Calculation = xlCalculationAutomatic
.ScreenUpdating = True
End With
End Sub
Private Sub unLock()
Dim wSheet As Worksheet
Dim Pwd As String
Pwd = "PASSWORD"
With Application
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With
Application.DisplayAlerts = False
On Error Resume Next
For Each wSheet In Worksheets
wSheet.Unprotect Password:=("PASSWORD")
Next wSheet
On Error GoTo 0
Application.DisplayAlerts = True
With Application
.Calculation = xlCalculationAutomatic
.ScreenUpdating = True
End With
End Sub
|
di Ackos (utente non iscritto) data: 14/07/2014 19:12:48
PS:
Ho anche provato a mettere VeryHidden i fogli che mi interessato e ad aggiungere un if dopo il For per il blocco, cioè:
For Each wSheet In Worksheets
If wSheet.Visible Then
[..]
End If
Next wSheet
ma non è cambiato nulla. La protezione del foglio viene comunque assegnata anche se i fogli sono VeryHidden a quanto pare..
di Vecchio Frac data: 15/07/2014 15:31:36
Prima di impartire un .Protect, devi assicurarti che il foglio wSheet che sta per essere protetto *non* sia uno di quelli impostati Hidden (o VeryHidden).
'in Enable_Me() e anche in lock()
....
For Each wSheet In Worksheets
if wSheet.Visible <> xlHidden and wSheet.visible<> xlVeryHidden then
wSheet.Protect "PASSWORD", userinterfaceonly:=True
....
End if |
Risolto!
di Ackos (utente non iscritto) data: 15/07/2014 16:45:16
Fantastico! Grazie mille!!
Vuoi Approfondire?