I faced a similar situation some months ago when saving XL files as web
pages. While Excel did a good job with the heavy lifting the html code still
needed some tweaking so I formulated this procedure:
'--beginning of code----
Sub ReplaceTextInFile( _
SourceFile As String, _
srchText As String, _
newText As String)
Dim BullpenFile As String
Dim tmpLine As String
Dim intLineCtr As Long
Dim F1 As Integer
Dim F2 As Integer
Dim blnContinueSrch As Boolean
BullpenFile = "RESULT.TMP"
If Dir(SourceFile) = "" Then
'No source file referenced
Exit Sub
End If
'If the temporary file already exists...delete it
If Dir(BullpenFile) <> "" Then
On Error Resume Next
Kill BullpenFile
On Error GoTo 0
If Dir(BullpenFile) <> "" Then
MsgBox BullpenFile & _
" already open, close and delete/rename the file and try
again.", _
vbCritical
Exit Sub
End If
End If
F1 = FreeFile
Open SourceFile For Input As F1
F2 = FreeFile
Open BullpenFile For Output As F2
intLineCtr = 1
application.StatusBar = "Reading data from " & BullpenFile & " ..."
blnContinueSrch = True
While Not EOF(F1)
'Set the status bar message
If intLineCtr Mod 100 = 0 Then
application.StatusBar = "Reading line #" & intLineCtr & " in " &
BullpenFile & " ..."
End If
'Read a line from the source file
Line Input #F1, tmpLine
If srchText <> "" Then
If blnContinueSrch = True Then
'perform the text replacement, if possible
blnContinueSrch = Not ReplaceTextInString( _
SourceString:=tmpLine, _
SearchString:=srchText, _
ReplaceString:=newText)
End If
End If
'Write the amended line to the temporary file
Print #F2, tmpLine
intLineCtr = intLineCtr + 1
Wend
application.StatusBar = "Closing files ..."
Close F1
Close F2
Kill SourceFile ' delete original file
Name BullpenFile As SourceFile ' rename temporary file
application.StatusBar = False
End Sub
'--end of code----
I create the .htm file via code and use this code to effect the changes I
need:
'--beginning of code----
ReplaceTextInFile _
SourceFile:=strDestPath & strDestFileName, _
srchText:="align=3dcenter x

ublishsource=", _
newText:="align=3dleft x

ublishsource="
'--end of code----
The code may not optimized, but for my uses it works just fine.
Is that something you can work with?
***********
Regards,
Ron
XL2002, WinXP-Pro