Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Junior Member
 
Posts: 2
Default Slight VBA hickup

I want the following code to refresh all my pivots (on protected sheets), then activate cell B2 on sheet "Source." The code does what I want when I run it in the VBA editor, but when I use the in-sheet button with the assigned macro, it never ends on the "Source" sheet. Am I missing a command after the final for loop. Any thoughts?

Private Sub FixSource()
'
' FixSource Macro
'
Dim ws As Worksheet
Dim pt As PivotTable
Dim pc As PivotCache

On Error Resume Next
For Each ws In ActiveWorkbook.Worksheets
ws.Unprotect Password:="password"
pt.PivotCache.MissingItemsLimit = xlMissingItemsNone
Next ws
For Each pc In ActiveWorkbook.PivotCaches
On Error Resume Next
pc.Refresh
Next pc

For Each ws In ActiveWorkbook.Worksheets
ws.Protect DrawingObjects:=True, _
Contents:=True, Scenarios:=True, _
Password:="password"
Next ws

Worksheets("Source").Select
Range("B2").Select


End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default Slight VBA hickup

Try this...

Private Sub FixSource2()

Dim ws As Worksheet, As PivotTable, As PivotCache

' On Error Resume Next
With ActiveWorkbook
For Each ws In .Worksheets
ws.Unprotect Password:="password"
pt.PivotCache.MissingItemsLimit = xlMissingItemsNone
Next 'ws

For Each pc In .PivotCaches: pc.Refresh: Next 'pc

For Each ws In .Worksheets
ws.Protect DrawingObjects:=True, Contents:=True, _
Scenarios:=True, Password:="password"
Next 'ws
End With 'ActiveWorkbook

Application.Goto Sheets("Source").Range("B2")
End Sub

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default Slight VBA hickup

missed something in copy/paste...

Private Sub FixSource2()

Dim ws As Worksheet, pt As PivotTable, pc As PivotCache

' On Error Resume Next
With ActiveWorkbook
For Each ws In .Worksheets
ws.Unprotect Password:="password"
pt.PivotCache.MissingItemsLimit = xlMissingItemsNone
Next 'ws

For Each pc In .PivotCaches: pc.Refresh: Next 'pc

For Each ws In .Worksheets
ws.Protect DrawingObjects:=True, Contents:=True, _
Scenarios:=True, Password:="password"
Next 'ws
End With 'ActiveWorkbook

Application.Goto Sheets("Source").Range("B2")
End Sub


--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion


  #4   Report Post  
Junior Member
 
Posts: 2
Default

This got set aside for the past week. Thanks so much for your reply. I will give it a try and let you know how ti works.

Thanks Again!

Quote:
Originally Posted by GS[_2_] View Post
missed something in copy/paste...

Private Sub FixSource2()

Dim ws As Worksheet, pt As PivotTable, pc As PivotCache

' On Error Resume Next
With ActiveWorkbook
For Each ws In .Worksheets
ws.Unprotect Password:="password"
pt.PivotCache.MissingItemsLimit = xlMissingItemsNone
Next 'ws

For Each pc In .PivotCaches: pc.Refresh: Next 'pc

For Each ws In .Worksheets
ws.Protect DrawingObjects:=True, Contents:=True, _
Scenarios:=True, Password:="password"
Next 'ws
End With 'ActiveWorkbook

Application.Goto Sheets("Source").Range("B2")
End Sub


--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion
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
Slight Annoyance cosmmarchy Excel Programming 1 November 3rd 12 02:15 AM
a slight syntax error... okrob Excel Programming 2 February 1st 08 05:44 PM
Need slight modification on macro below Sam Commar Excel Programming 0 April 26th 07 03:51 PM
Slight prob with this code simonsmith[_8_] Excel Programming 1 May 19th 06 02:37 PM
Slight Problem Nick Excel Discussion (Misc queries) 1 June 29th 05 04:54 PM


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

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

About Us

"It's about Microsoft Excel"