Renaming a sheet copied from another workbook, errors ensue...

Gingertrees

Well-known Member
Joined
Sep 21, 2009
Messages
697
Gaaah! Working on a macro to copy in a sheet from a daily report, into my "processing" workbook. The daily report worksheet to-be-copied will always be called "orange", so I figured when I copy it, I'll rename it "orange" + the number of sheets in the workbook (orange5 when sheets.count=5, orange 11 when sheets.count=11, etc.)
Unfortunately, I continue to get the Runtime error 438: Object doesn't support this property or method.

What am I doing wrong???
Code:
Sub OpenCopyOrange()


Application.ScreenUpdating = False
Application.DisplayAlerts = False
Application.Calculation = xlCalculationAutomatic


Dim tempfiletocopy As Variant
Dim tempfileName As String


Dim sheet As Worksheet


'//open downloaded floor schedule
tempfiletocopy = Application.GetOpenFilename
Workbooks.Open tempfiletocopy
tempfileName = ActiveWorkbook.Name


Sheets("ORANGE").Copy After:=Workbooks("ORANGEA.xlsm").Sheets(Sheets.Count)


'///!/!/Here is where it errors!/!/!/!/!/!/!/!/!/!/!/!/!/
ActiveSheet.Name = "Orange" & (Workbooks("ORANGEA.xlsm").Sheets(Sheets.Count))
'///!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/


Workbooks(tempfileName).Close savechanges:=False


Application.ScreenUpdating = True
Application.DisplayAlerts = True


End Sub

If anyone has a cool "SheetExists" error handler, that does more than tell me "this sheet name exists - deal with it.", that would be helpful, too.
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Try:
Code:
ActiveSheet.Name = "Orange" & Sheets.Count

here's a UDF you can use to test if a sheet name already exists:
Code:
Function SheetExists(shName As String) As Boolean
SheetExists = False
For Each sh In .Sheets
    If sh.Name = shName Then
        SheetExists = True
        Exit For
    End If
 Next sh
End Function
Example of use in your code:
If Not SheetExists("Orange" & Sheets.Count) then
ActiveSheet.Name = "Orange" & Sheets.Count
Else
'Some other name
End If
[/code]
 
Upvote 0

Forum statistics

Threads
1,215,053
Messages
6,122,882
Members
449,097
Latest member
dbomb1414

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