Ask Question Forum:
C
O
M
P
U
T
E
R
2
8
- Underline
- Bold
- Italic
- Indent
- Step
- Bullet
- Quote
- Cut
- Copy
- Paste
- Table
- Spelling
- Find & Replace
- Undo
- Redo
- Link
- Attach
- Clear
- Code
Y-position of the mouse cursor
Attachment:===
Replace text right after at first character position in search text in html by MS Excel 2003 VBA

and insert other new text code rigth below the search location in html file. Please
see the following code area for Function searchtext2(), Now I would like to modify
searchtext2() for a new function that is replace a text right after first character position in search a text location in html by VBA coding, For example, search ("shLink")[0] and will be reaplced by ("shLink"[g_iSh]
Example.HTM
==================================
"<frame src=""+document.all.item("shLink")[0].href+"" name="frSheet" noresize>"+
Plese advise
Duncan
Sub searchtext2()Dim workbookname As StringDim searchtext As StringDim ReplaceText As StringDim rFile As Stringworkbookname = ActiveWorkbook.Path & "example.htm"searchtext = "<script language=""JavaScript"">"ReplaceText = searchtext & vbCrLf & " var g_iSh = 0;" & vbCrLf & _ "if (window.location.search)" & vbCrLf & _ "g_iSh = window.location.search.split(/=/)[1];" & vbCrLf & _ "window.setInterval(""refreshPage()"", 10000); //refresh every 10 sec" & vbCrLfrFile = ReadFile(workbookname)rFile = Replace$(rFile, searchtext, ReplaceText, 1, , vbTextCompare)WriteFile workbookname, rFileEnd SubSub WriteFile(sFilePathAndName, sFileContents)Dim oFSDim oFSFile Const ForWriting = 2 Set oFS = CreateObject("Scripting.FileSystemObject") Set oFSFile = oFS.OpenTextFile(sFilePathAndName, ForWriting, True) oFSFile.write (sFileContents) oFSFile.Close Set oFSFile = Nothing Set oFS = NothingEnd SubFunction ReadFile(sFilePathAndName) Dim sFileContents Dim oFS Dim oTextStream Set oFS = CreateObject("Scripting.FileSystemObject") If oFS.FileExists(sFilePathAndName) = True Then Set oTextStream = oFS.OpenTextFile(sFilePathAndName, 1) sFileContents = oTextStream.ReadAll oTextStream.Close Set oTextStream = Nothing End If Set oFS = Nothing ReadFile = sFileContentsEnd Function
1:2:3:4:5:6:7:8:9:10:11:12:13:14:15:16:17:18:19:20:21:22:23:24:25:26:27:28:29:30:31:32:33:34:35:36:37:38:39:40:41:42:43:44:45:46:47:48:49:50:51:52:53:54:55:56:57:58:59:60:61:62:63:64:65:66:
Okay now understand. it should be no problem because
it used 'ReplaceText = searchtext & vbCrLf & " var g_iSh = 0;" & vbCrLf to
keep"<script text>
Okay now understand. it should be no problem because
it used 'ReplaceText = searchtext & vbCrLf & " var g_iSh = 0;" & vbCrLf to
keep"<script text>
Okay now understand. it should be no problem because
it used 'ReplaceText = searchtext & vbCrLf & " var g_iSh = 0;" & vbCrLf to
keep"<script text>
Okay now understand. it should be no problem because
it used 'ReplaceText = searchtext & vbCrLf & " var g_iSh = 0;" & vbCrLf to
keep"<script text>