Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 46
Default protect in macro

I have the following code in a Macro to refresh an external database query.

Sheets("Client & Staff Data").Select
ActiveSheet.Unprotect Password:="pancake"
ActiveWorkbook.RefreshAll

Range("M3:N3").Select
Selection.AutoFill Destination:=Range("M3:N98"), Type:=xlFillDefault
ActiveSheet.Protect Password:="pancake"

When I test it by stepping through the code using F8 it works perfectly. But
when I activate it with a button, I get two messages that I need to first
unprotect the sheet. Why is it working when tested but not on the button?
Regards
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 98
Default protect in macro


1. Did you manually unprotected the sheet checked the password?
2. Are you working on more then 1 workbook. If two workbooks has same
worksheet name then it may create issue.
3. Have you linked the correct macro to the button.

Check these things.
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default protect in macro


Hello pkeegs,

Running the code manually removes the protection before the query is
run. If the query is running automatically, the protection will have to
removed before the refresh and applied after the refresh. The Query
object generates 2 events *BeforeRefresh* and *AfterRefresh*. To use the
events in VBA requires creating a custom Class with events. This is
quite involved technique and not practical to attempt to explain here.
Chip Pearson has a good write up on this 'Application Events'
(http://www.cpearson.com/excel/AppEvent.aspx)

Sincerely,
Leith Ross


--
Leith Ross
------------------------------------------------------------------------
Leith Ross's Profile: http://www.thecodecage.com/forumz/member.php?userid=75
View this thread: http://www.thecodecage.com/forumz/sh...ad.php?t=48227

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 46
Default protect in macro

Thanks for the reply:
1. The sheet was protected before I ran the macro
2. Only working on one sheet
3. I have checked the macro allocated to the button - it is correct

"Heera" wrote:


1. Did you manually unprotected the sheet checked the password?
2. Are you working on more then 1 workbook. If two workbooks has same
worksheet name then it may create issue.
3. Have you linked the correct macro to the button.

Check these things.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 46
Default protect in macro

Thanks Leth,

I'll have to study what you are saying & check with Pearson - but it seems
to me that I am unprotecting before the refresh and protecting after the
refresh, but there must be more to this than I am seeing.

"Leith Ross" wrote:


Hello pkeegs,

Running the code manually removes the protection before the query is
run. If the query is running automatically, the protection will have to
removed before the refresh and applied after the refresh. The Query
object generates 2 events *BeforeRefresh* and *AfterRefresh*. To use the
events in VBA requires creating a custom Class with events. This is
quite involved technique and not practical to attempt to explain here.
Chip Pearson has a good write up on this 'Application Events'
(http://www.cpearson.com/excel/AppEvent.aspx)

Sincerely,
Leith Ross


--
Leith Ross
------------------------------------------------------------------------
Leith Ross's Profile: http://www.thecodecage.com/forumz/member.php?userid=75
View this thread: http://www.thecodecage.com/forumz/sh...ad.php?t=48227


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
Protect a Macro Darin Kramer Excel Programming 5 May 9th 06 05:09 PM
protect a macro kwiklearner[_11_] Excel Programming 2 March 30th 06 02:42 PM
Protect Macro Joe Excel Programming 1 August 13th 04 07:19 AM
protect a macro rbanks[_8_] Excel Programming 2 November 21st 03 09:03 PM
protect - macro? Stu[_31_] Excel Programming 13 October 20th 03 01:48 AM


All times are GMT +1. The time now is 11:34 PM.

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"