Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 100
Default Strange Replace Failure

Greetings! My VBA macro has executed the following instruction correctly
without any problems about 60 times a month for the last year in order to
remove any blanks from the name of the active sheet:

ActiveSheet.Name = Replace(ActiveSheet.Name, " ", "")

This evening when my macro executed this instruction, I could see that it
failed to remove the one blank from the sheet name, and VBA presented me with
the following error message: "Run-time error '1004': Cannot rename a sheet to
the same name as another sheet, a referenced object library or a work book
referenced by Visual Basic"

Does anyone have any ideas as to what might have caused this? Thanks!

--
May you have a most blessed day!

Sincerely,

Michael Fitzpatrick
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Strange Replace Failure

The workbook might have got another sheetname with the same name as the
active sheet (without spaces)
eg:

Sheet 1
Sheet1

If you try to rename the first sheet it will return this error

If this post helps click Yes
---------------
Jacob Skaria


"MichaelDavid" wrote:

Greetings! My VBA macro has executed the following instruction correctly
without any problems about 60 times a month for the last year in order to
remove any blanks from the name of the active sheet:

ActiveSheet.Name = Replace(ActiveSheet.Name, " ", "")

This evening when my macro executed this instruction, I could see that it
failed to remove the one blank from the sheet name, and VBA presented me with
the following error message: "Run-time error '1004': Cannot rename a sheet to
the same name as another sheet, a referenced object library or a work book
referenced by Visual Basic"

Does anyone have any ideas as to what might have caused this? Thanks!

--
May you have a most blessed day!

Sincerely,

Michael Fitzpatrick

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 100
Default Strange Replace Failure

Greetings! Fortunately I saved the workbook. And I noticed that there was
already a worksheet with the name my macro was trying to rename this
worksheet as. Somehow my macro must have restarted. This never happened
before.

Nice catch! Thanks a million.
--
May you have a most blessed day!

Sincerely,

Michael Fitzpatrick


"Jacob Skaria" wrote:

The workbook might have got another sheetname with the same name as the
active sheet (without spaces)
eg:

Sheet 1
Sheet1

If you try to rename the first sheet it will return this error

If this post helps click Yes
---------------
Jacob Skaria


"MichaelDavid" wrote:

Greetings! My VBA macro has executed the following instruction correctly
without any problems about 60 times a month for the last year in order to
remove any blanks from the name of the active sheet:

ActiveSheet.Name = Replace(ActiveSheet.Name, " ", "")

This evening when my macro executed this instruction, I could see that it
failed to remove the one blank from the sheet name, and VBA presented me with
the following error message: "Run-time error '1004': Cannot rename a sheet to
the same name as another sheet, a referenced object library or a work book
referenced by Visual Basic"

Does anyone have any ideas as to what might have caused this? Thanks!

--
May you have a most blessed day!

Sincerely,

Michael Fitzpatrick

  #4   Report Post  
Posted to microsoft.public.excel.programming
r r is offline
external usenet poster
 
Posts: 125
Default Strange Replace Failure

Sub test1()
Dim s As String

s = Replace(ActiveSheet.Name, " ", "")

If WsExist(ActiveWorkbook, s) Then
Err.Raise 1001, , "Cannot rename a sheet"
Else
ActiveSheet.Name = s
End If
End Sub

Function WsExist(Wb As Excel.Workbook, _
WsName As String) As Boolean
On Error Resume Next
WsExist = IsObject(Wb.Worksheets(WsName))
End Function

regards
r

Il mio ultimo lavoro ...
http://excelvba.altervista.org/blog/...ternative.html


"MichaelDavid" wrote:

Greetings! Fortunately I saved the workbook. And I noticed that there was
already a worksheet with the name my macro was trying to rename this
worksheet as. Somehow my macro must have restarted. This never happened
before.

Nice catch! Thanks a million.
--
May you have a most blessed day!

Sincerely,

Michael Fitzpatrick


"Jacob Skaria" wrote:

The workbook might have got another sheetname with the same name as the
active sheet (without spaces)
eg:

Sheet 1
Sheet1

If you try to rename the first sheet it will return this error

If this post helps click Yes
---------------
Jacob Skaria


"MichaelDavid" wrote:

Greetings! My VBA macro has executed the following instruction correctly
without any problems about 60 times a month for the last year in order to
remove any blanks from the name of the active sheet:

ActiveSheet.Name = Replace(ActiveSheet.Name, " ", "")

This evening when my macro executed this instruction, I could see that it
failed to remove the one blank from the sheet name, and VBA presented me with
the following error message: "Run-time error '1004': Cannot rename a sheet to
the same name as another sheet, a referenced object library or a work book
referenced by Visual Basic"

Does anyone have any ideas as to what might have caused this? Thanks!

--
May you have a most blessed day!

Sincerely,

Michael Fitzpatrick

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
Strange behaviour with replace function [email protected] Excel Programming 4 August 19th 08 02:38 PM
Strange find and replace query MJKelly Excel Programming 1 March 28th 08 03:56 PM
find and replace macro strange behaviour Nicawette Excel Discussion (Misc queries) 3 June 13th 06 08:49 PM
cell.replace strange behaviour Nicawette Excel Programming 5 June 13th 06 08:29 PM
What is this Strange Characet? Find/Replace D[_6_] Excel Programming 12 November 25th 04 06:33 AM


All times are GMT +1. The time now is 07:14 AM.

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"