Logo 
Search:

MS Office Answers

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds
  Question Asked By: Abbie Cohen   on Jan 14 In MS Office Category.

  
Question Answered By: Hollie Hughes   on Jan 14

Since it takes a long time, Autosave wouldn't be trying to come in as
the macro's running would it?

How about avoiding the sheet activations?:

On Error GoTo EH
Counter = 0
For Each sht In Application.ActiveWorkbook.Worksheets
Counter = Counter + 1
With sht.PageSetup

...page setup stuff here

End With
'ActiveSheet.Next.Select (commented out)
Next sht
Exit_EH:
etc.

worked OK on 192 empty sheets  here (XL2003)


ps. I realise that your macro works from the currently active sheet to
the last sheet, whereas mine does all the sheets regardless, but it
could help in diagnosis of the fault. If there ends up being no fault,
then you could perhaps pop in an IF statement of the ilk:

With sht.PageSetup
If .CenterFooter <> "CONFIDENTIAL" & Chr(10) & "Subject to Protective
Order" & Chr(10) & "USDC-KS 05-1368" Then
...page setup stuff here
End If
End With

Or if you want to only affect sheets from the active sheet add  an IF
which sets a flag when the active sheet is reached:

ActiveSheetReached = False
For Each sht In Application.ActiveWorkbook.Worksheets
If sht = ActiveSheet Then activeSheetReached = True
If activeSheetReached Then
Counter = Counter + 1
With sht.PageSetup
...page setup stuff herre
End With
End If
(you might want to put the Counter increment line elsewhere)

If you want the sheet with the error on it to become the active sheet
would a:
sht.activate
in the error handler do it?

Share: 

 

This Question has 9 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on Selection Method of Worksheet class failed Or get search suggestion and latest updates.


Tagged: