Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 131
Default Protecting sheet with update vba script

You can pass UserInterfaceOnly=True with Protect method to allow macros:

Sub ProtectUIOnly()

Sheet1.Protect Password:="password", _
UserInterfaceOnly:=True

Sheet1.Cells(1, 1) = "test"

End Sub

--
urkec


"Clayton Dool" wrote:

I have a workbook with multiple sheets. When trying to protect the
sheets, I can no longer update the data and underlying pivot tables
programmatically. How do I approach this?




Workbook
----------------------------------
- Sheet 1
- Contains Query Table linked to SQL
- (HIDDEN)
- Contains dummy cell that has formula that causes
Worksheet_Calculation to be run when query
is refreshed.
- Sheet 2, 3, and 4
- Contain Pivot Tables referencing Query Table Above
- Contain button that runs code that refreshes data.



Code/Macro
-------------------------------
Sub RefreshData()
Dim iP As Integer
Dim iW As Integer

For iW = 1 To Worksheets.Count
If (Worksheets(iW).Name = "Data") Then
Worksheets(iW).QueryTables("DataQuery").Refresh
BackgroundQuery:=False
End If
Next
End Sub



Private Sub Worksheet_Calculate()
Dim iP As Integer
Dim iW As Integer

Application.DisplayAlerts = False
Application.ScreenUpdating = False

For iW = 1 To Worksheets.Count
For iP = 1 To Worksheets(iW).PivotTables.Count
Worksheets(iW).PivotTables(iP).RefreshTable
Next
Next

Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub




Thanks,
Clayton

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
protecting formulas without protecting sheet so grouping still wor JM Excel Discussion (Misc queries) 1 June 4th 09 06:42 AM
update excel files using a vba script adinic[_13_] Excel Programming 8 April 17th 06 09:53 PM
Update a workbook from a script [email protected] Excel Discussion (Misc queries) 1 March 8th 06 02:30 PM
update Link from protected wb OR prompt for protecting a worksheet zand Excel Programming 1 January 18th 06 07:04 PM
Script or Tool to Update Excel Links Just_Buy Excel Programming 1 April 13th 04 11:08 PM


All times are GMT +1. The time now is 01:35 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"