Compile error: invalid outside procedure

dowcraig

New Member
Joined
Jan 14, 2009
Messages
36
Hi there,
I'm making changes to row A, but am getting an invalid outside procedure, not sure why. Don't even know what it means. It's not even in the same worksheet.

This is my Macro:
' UpcomingClosings Macro
'
'
Range("B4:I100").Select
ActiveWorkbook.Worksheets("Upcoming Closings").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Upcoming Closings").Sort.SortFields.Add(Range( _
"H4:H100"), xlSortOnCellColor, xlAscending, , xlSortNormal).SortOnValue.Color _
= RGB(255, 255, 255)
ActiveWorkbook.Worksheets("Upcoming Closings").Sort.SortFields.Add Key:=Range _
("H4:H100"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("Upcoming Closings").Sort
.SetRange Range("B3:I100")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Then it all needs to go into that BeforeSave event routine.
 
Upvote 0
I've put them all in the "ThisWorkbook" sheet, but get a:
Compile error:
Ambiguous name detected: Workbook_BeforeSave

What does this mean?


Private Sub Workbook_BeforeSave(Cancel As Boolean)
'
' OutstandingGifts Macro
'
'
Range("B4:F100").Select
ActiveWorkbook.Worksheets("Outstanding Gifts").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Outstanding Gifts").Sort.SortFields.Add(Range( _
"D4:D100"), xlSortOnCellColor, xlAscending, , xlSortNormal).SortOnValue.Color _
= RGB(255, 255, 255)
ActiveWorkbook.Worksheets("Outstanding Gifts").Sort.SortFields.Add Key:=Range _
("D4:D100"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("Outstanding Gifts").Sort
.SetRange Range("B4:F100")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub
Private Sub Workbook_BeforeSave(Cancel As Boolean)
'
' UpcomingClosings Macro
'
'
Range("B4:I100").Select
ActiveWorkbook.Worksheets("Upcoming Closings").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Upcoming Closings").Sort.SortFields.Add(Range( _
"H4:H100"), xlSortOnCellColor, xlAscending, , xlSortNormal).SortOnValue.Color _
= RGB(255, 255, 255)
ActiveWorkbook.Worksheets("Upcoming Closings").Sort.SortFields.Add Key:=Range _
("H4:H100"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("Upcoming Closings").Sort
.SetRange Range("B3:I100")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub
 
Upvote 0
You can only have one routine with that name. All of your code needs to be within that one routine (or called from it) if you want it to run when the workbook is saved.
 
Upvote 0

Forum statistics

Threads
1,215,886
Messages
6,127,583
Members
449,385
Latest member
KMGLarson

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top