Solved

Protected worksheet Refresh table(not pivot)

Posted on 2016-07-26
6
61 Views
Last Modified: 2016-07-27
I need to protect my worksheet, but still be able to refresh the underlying data(table).  

My worksheet is an Invoice with the body of the invoice is a table linked to underlying query.  How do I refresh this data when I have locked down (protected worksheet) w/password?  The only code I can find seems to unlock & Lock by storing the password within the VBA.   There has to be another method.
0
Comment
Question by:Karen Schaefer
  • 3
  • 3
6 Comments
 
LVL 1

Accepted Solution

by:
Lawrence Salvucci earned 500 total points
ID: 41730430
This is how I do it. I have some VBA code that will unlock the sheet, then refresh the table, then lock the sheet again. You can just put the "RefreshConnections" function on a command button on your worksheet somewhere. Then the user just clicks on the button and it runs that code and does everything I mentioned. There are 4 pieces of code that I use. Just change the ("strsIVAL") to the sheet name and change the "strs" to the password you want to use to lock your sheet. Change that in both the UNLOCKSHEETS & LOCKSHEETS code below. Then change the name of the file ("Stocking Program Monitor.xlsm") in the REFRESHALLCONNECTIONS code below. Put all this in a module and then put the RefreshConnections code linked to a command button. Or just run the macro from the "View Macros" popup screen.

Sub UnlockSheets()
Worksheets("strsIVAL").Unprotect Password:="strs"
End Sub

Sub LockSheets()
Worksheets("strsIVAL").Protect Password:="strs"
End Sub

Sub RefreshAllConnections()
Workbooks("Stocking Program Monitor.xlsm").RefreshAll
End Sub

Sub RefreshConnections()
UnlockSheets
RefreshAllConnections
LockSheets
End Sub

Open in new window

0
 

Author Closing Comment

by:Karen Schaefer
ID: 41731508
Thanks that did the trick.  Quick question is there a way to standardize this so it can be used in multiple workbooks.  Global variable?  active workbook instead of hard coding the workbook name?
0
 
LVL 1

Expert Comment

by:Lawrence Salvucci
ID: 41731527
Yes there is. I will post something when I get back to my office. Give me a little bit.
0
Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 

Author Comment

by:Karen Schaefer
ID: 41731530
ok thanks
0
 
LVL 1

Expert Comment

by:Lawrence Salvucci
ID: 41731699
You can use this code to lock and unlock the sheets. This will just unlock or lock all the sheets. You still need to hard code the password though.

Sub LockSheets()
Dim ws As Worksheet
Dim pwd As String

pwd = "BC1958"  ' Put your password here
For Each ws In Worksheets
    ws.Protect Password:=pwd
Next ws
End Sub

Sub UnlockSheets()
Dim ws As Worksheet
Dim pwd As String

pwd = "BC1958"  ' Put your password here
For Each ws In Worksheets
    ws.Unprotect Password:=pwd
Next ws

End Sub

Open in new window


Then you can use this to refresh your connection to your table

Sub RefreshAllConnections()
Workbooks(ThisWorkbook.Name).RefreshAll
End Sub

Open in new window


Let me know if you need anything else.
0
 

Author Comment

by:Karen Schaefer
ID: 41731823
thanks that's great.
0

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
EXCEL 2013 question. 4 28
how to add loop into this VBA 3 29
Excel VBA 4 27
Excel - conditional formatting on several columns 9 33
Introduction While answering a recent question (http:/Q_27311462.html), I created an alternative function to the Excel Concatenate() function that you might find useful.  I tested several solutions and share the results in this article as well as t…
This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question