Guys and Gals, I did a search and didn't really see anything that helped me (I hope I didn't miss anything...).
I wrote a macro a few weeks ago and everything worked fine. The overall macro was this:
call a form, initialize the form, run the code (the code looked to # of sheets and put variables into the header and footer on each sheet), exit and done.
now when I run it I have two problems. first, I can't update the page footer. I get an error with .LeftFooter. I'm not too concerned with this because it's a small problem.
The problem I'm having is that after all the sheets update, Excel will crash (sometimes) when I click on other tabs. I first found this out when trying to run another macro, all this macro did was Sheets("xx").select . So I think it's some kind of error when after running this macro without errors, then trying to switch to another tab/sheet.
Here is my code for the form (I used most of it from a progress bar example and tweaked it for my use... but it did work in my form for a while):
____________________________________________________________________________
Option Explicit
Private Sub UserForm_Activate()
Application.Cursor = xlWait
ProgressBar.MousePointer = fmMousePointerHourGlass
DoEvents
Call CalculateData
Application.Cursor = xlDefault
Unload Me
End Sub
Private Sub UserForm_Initialize()
TextBox2.Left = TextBox1.Left
TextBox2.Top = TextBox1.Top + 3
TextBox2.Width = 0
End Sub
Sub CalculateData()
Dim i, n As Integer
Dim sheetCount As Integer
Dim agencyName, agentName, DOF, FDL, territory, confidential As String
i = 1
n = 1
sheetCount = Sheets.Count
agencyName = Range("B2").Value
agentName = Range("B4").Value
DOF = Range("B6").Value
FDL = Range("B8").Value
territory = Range("B10").Value
confidential = Range("B24").Value
For i = 1 To sheetCount
ProgressBar.TextBox2.Width = (n / (sheetCount * 2)) * 200
ProgressBar.status.Caption = Int(n / (sheetCount * 2) * 100) & "% Complete"
DoEvents
n = n + 1
With Sheets(i).PageSetup
.LeftHeader = agencyName & Chr(10) & agentName & Chr(10) & DOF & Chr(10) & FDL & Chr(10) & territory
End With
ProgressBar.TextBox2.Width = (n / (sheetCount * 2)) * 200
ProgressBar.status.Caption = Int(n / (sheetCount * 2) * 100) & "% Complete"
DoEvents
n = n + 1
With Sheets(i).PageSetup
' .LeftFooter = confidential '& Chr(10) & "&D &T" & Chr(10) & "&Z&F"
End With
Next i
End Sub
____________________________________________________________________________
Again, this macro runs fine (when .LeftFooter is commented out). It's after this is said and done, I crash when I try to select another tab.
Additional information that might help is that I have some public variables defined, but they are not used in this macro.
I appreciate any help or suggestions.
I wrote a macro a few weeks ago and everything worked fine. The overall macro was this:
call a form, initialize the form, run the code (the code looked to # of sheets and put variables into the header and footer on each sheet), exit and done.
now when I run it I have two problems. first, I can't update the page footer. I get an error with .LeftFooter. I'm not too concerned with this because it's a small problem.
The problem I'm having is that after all the sheets update, Excel will crash (sometimes) when I click on other tabs. I first found this out when trying to run another macro, all this macro did was Sheets("xx").select . So I think it's some kind of error when after running this macro without errors, then trying to switch to another tab/sheet.
Here is my code for the form (I used most of it from a progress bar example and tweaked it for my use... but it did work in my form for a while):
____________________________________________________________________________
Option Explicit
Private Sub UserForm_Activate()
Application.Cursor = xlWait
ProgressBar.MousePointer = fmMousePointerHourGlass
DoEvents
Call CalculateData
Application.Cursor = xlDefault
Unload Me
End Sub
Private Sub UserForm_Initialize()
TextBox2.Left = TextBox1.Left
TextBox2.Top = TextBox1.Top + 3
TextBox2.Width = 0
End Sub
Sub CalculateData()
Dim i, n As Integer
Dim sheetCount As Integer
Dim agencyName, agentName, DOF, FDL, territory, confidential As String
i = 1
n = 1
sheetCount = Sheets.Count
agencyName = Range("B2").Value
agentName = Range("B4").Value
DOF = Range("B6").Value
FDL = Range("B8").Value
territory = Range("B10").Value
confidential = Range("B24").Value
For i = 1 To sheetCount
ProgressBar.TextBox2.Width = (n / (sheetCount * 2)) * 200
ProgressBar.status.Caption = Int(n / (sheetCount * 2) * 100) & "% Complete"
DoEvents
n = n + 1
With Sheets(i).PageSetup
.LeftHeader = agencyName & Chr(10) & agentName & Chr(10) & DOF & Chr(10) & FDL & Chr(10) & territory
End With
ProgressBar.TextBox2.Width = (n / (sheetCount * 2)) * 200
ProgressBar.status.Caption = Int(n / (sheetCount * 2) * 100) & "% Complete"
DoEvents
n = n + 1
With Sheets(i).PageSetup
' .LeftFooter = confidential '& Chr(10) & "&D &T" & Chr(10) & "&Z&F"
End With
Next i
End Sub
____________________________________________________________________________
Again, this macro runs fine (when .LeftFooter is commented out). It's after this is said and done, I crash when I try to select another tab.
Additional information that might help is that I have some public variables defined, but they are not used in this macro.
I appreciate any help or suggestions.