Problems ReplaceFormat - error 1004

N

ndsykes

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...
 
N

ndsykes

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top