View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
AndreLaplume AndreLaplume is offline
external usenet poster
 
Posts: 1
Default RefreshAll / Protect Help Required


Hello....
Here is my delima. I created a spreadsheet with data tabs that pul
data from an MsAccess database. I added coded to the Project Explore
/ This WOrkBook / Open area such that when the workbook opens:

1) All data tabs are refreshed
2) All data tabs are protected
3) The file is saved under a new name.


*There is an IF THE ELSE condition so that the On-Open codes onl
executes 1 - 3 when the 'template' file is opened.

** I did not want to set the data tabs to refresh on open since user
are not secured to connect to the Access dbs.

The good news is this all works fine!!!

The bad news is I really want to add code to open the Excel file int
Ms Access.

So, in access I created a macro. It has a bunch of OpenQuer
statements that build the tables the Ecxel data tabs need. It the
issues a RunnApp with a command line:

Excel "G:\DBS\MyDbs\TEMPLATE.xls"

So, Access should runs some queries then open the Excel template whic
should, on-open refresh the tables, protect them and save the file.

Access opens the Excel file and starts refreshing the data tabs bu
before it has finished refreshing then the protect command is executed
one oir more of the tabs are protected and you get a message saying the
must be unprotected before they can be refreshed!

Again, if I run the Access queries then shut Access then opne the Exce
file...everything works fine. If I let Access invoke Excel, essentiall
is does not wait for the data tabs to refresh before protecting them.

Here is a snoppit of how I refresh and protect:




'Refresh All Linked Data
ActiveWorkbook.RefreshAll

'Protect Sheets
For I = 1 To 8
Sheets("Doc" & I & "Data").Protect DrawingObjects:=True
Contents:=True, Scenarios:=True, Password:="Protect"
Next I


ANY IDEAS????

--
AndreLaplum
-----------------------------------------------------------------------
AndreLaplume's Profile: http://www.excelforum.com/member.php...fo&userid=2680
View this thread: http://www.excelforum.com/showthread.php?threadid=40057