Jim, Been working on this and some other projects, but here is what I have:
Sub Workbook_Open()
Dim pw As String: pw = "test"
With Sheets("Distribution").Select
Sheets("Distribution").Protect pw, UserInterfaceOnly:=True
Sheets("Totals").Select
Sheets("Totals").Protect pw, UserInterfaceOnly:=True
Sheets("FY").Select
Sheets("FY").Protect pw, UserInterfaceOnly:=True
Sheets("FY").Select
ActiveSheet.Unprotect pw
Sheets("Totals").Select
ActiveSheet.Unprotect pw
ActiveWorkbook.RefreshAll
Sheets("FY").Select
Sheets("FY").Protect pw, UserInterfaceOnly:=True
End With
With Sheets("Totals").Select
Sheets("Totals").Protect pw, UserInterfaceOnly:=True
Sheets("Distribution").Select
BlankRow = Range("A65536").End(xlUp).Row
Range("A" & (BlankRow + 1)).Select
End With
End Sub
This is in the 'ThisWorkbook' module and works to a point. It will protect
every sheet I want and will unprotect those that need to be updated by the
SQL. The problem is that even though the 'ActiveWorkbook.RefreshAll' comes
before the 'Totals' sheet is protected, I cannot protect the 'Totals' sheet
or the SQL will not fire in time...at least that is how it appears. When I
run this, I get sent to the first blank line with the code below before the
popup appears asking if I want to Enable or Disable automatic refresh, which
is when the database data is being imported.
Sheets("Distribution").Select
BlankRow = Range("A65536").End(xlUp).Row
Range("A" & (BlankRow + 1)).Select
I tried adding
Sub LockTotals()
Dim pw As String: pw = "test"
With Sheets("Totals").Select
Sheets("Totals").Protect pw, UserInterfaceOnly:=True
Sheets("Distribution").Select
BlankRow = Range("A65536").End(xlUp).Row
Range("A" & (BlankRow + 1)).Select
End With
End Sub
to the end of the main code and calling it with no success. I tried placing
it in the sheet where all the data is being entered but that did not work
either...which is good because it would have fired every time the user made
an entry which would slow things down a lot.
I am still hoping someone can see a way to do this.
Thanks,
Andrew