Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Problems ReplaceFormat - error 1004

I have a load of workbooks within which I need to change any cells
formatted with dollars to pounds. I have written this macro to do it:

Sub ChangeDollarsToPounds()

Dim Filename As String
Dim wb As Workbook
Dim ws As Worksheet

Filename = Dir("C:\Templates\*.xls")
Do While Filename < ""
Set wb = Workbooks.Open("C:\Templates\" & Filename)
Set ws = wb.Worksheets("Data")

Application.FindFormat.NumberFormat = "[$$-409]#,##0"
Application.ReplaceFormat.NumberFormat = "[$
£-809]#,##0" '**** code crashes here ****
ws.Cells.Replace What:="", Replacement:="", LookAt:=xlPart,
SearchOrder:= _
xlByRows, MatchCase:=False, SearchFormat:=True,
ReplaceFormat:=True

wb.Save
wb.Close

Filename = Dir()
Loop

End Sub

....however, the code always crashes with Error 1004 : Application or
Object defined error at the line shown. This code was lifted directly
from a recorded macro, but it seems that if I try to use it in any
workbooks other than the one it was recorded in it crashes at that
line.

I even tried copying the recorded code directly into a blank workbook
and running it and it also failed at the same place.

Any advice would be gratefully received...

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default Problems ReplaceFormat - error 1004

I'm not sure, but have you tried changing "Application" to "ws" in the code.

"ndsykes" wrote:

I have a load of workbooks within which I need to change any cells
formatted with dollars to pounds. I have written this macro to do it:

Sub ChangeDollarsToPounds()

Dim Filename As String
Dim wb As Workbook
Dim ws As Worksheet

Filename = Dir("C:\Templates\*.xls")
Do While Filename < ""
Set wb = Workbooks.Open("C:\Templates\" & Filename)
Set ws = wb.Worksheets("Data")

Application.FindFormat.NumberFormat = "[$$-409]#,##0"
Application.ReplaceFormat.NumberFormat = "[$
£-809]#,##0" '**** code crashes here ****
ws.Cells.Replace What:="", Replacement:="", LookAt:=xlPart,
SearchOrder:= _
xlByRows, MatchCase:=False, SearchFormat:=True,
ReplaceFormat:=True

wb.Save
wb.Close

Filename = Dir()
Loop

End Sub

....however, the code always crashes with Error 1004 : Application or
Object defined error at the line shown. This code was lifted directly
from a recorded macro, but it seems that if I try to use it in any
workbooks other than the one it was recorded in it crashes at that
line.

I even tried copying the recorded code directly into a blank workbook
and running it and it also failed at the same place.

Any advice would be gratefully received...


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Problems ReplaceFormat - error 1004

Unfortunately, the FindFormat and ReplaceFormat properties only apply
to the Application object, so can't be changed to the worksheet object
in that way.

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
Replaceformat problem davethewelder Excel Discussion (Misc queries) 2 March 3rd 08 05:08 PM
Run Time 1004 Error: Application or Object Difine Error BEEJAY Excel Programming 0 October 17th 06 10:45 PM
SearchFormat and ReplaceFormat Mike Excel Programming 1 October 24th 05 02:38 PM
run-time error '1004': Application-defined or object-deifined error [email protected] Excel Programming 5 August 10th 05 09:39 PM


All times are GMT +1. The time now is 12:25 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"