CalYu
Technical User
- Oct 7, 2008
- 3
Hello there,
Totally new to VBS scripts, my program is not elegant (and its the third attempt). I've searched for the solution for what i want to do - which should seem obvious but ...nothing.
In a nutshell i want to assign something like this
ins3 = ".jpg></A></i></h1><table border="
and be able to do a replace for
HtmlFile = Replace(HtmlFile,"</i></h1><table border=",name3)
Purpose is to insert a jpg (or whatever) file in a large (like 7000) number of html files, each of the htmls contains a table - that's where the pic should go.
Thanks in advance
This is the code
On Error Resume Next
Dim ArrAll()
Const adOpenStatic = 3
Const adLockOptimistic = 3
Const adCmdText = &H0001
Const ForReading = 1
Const ForAppending = 8
Const ForWritting = 2
name2 = ".html"
Ins1 = "<IMG SRC ="
'*****************************************
ins3 = ".jpg></A></i></h1>
'*****************************************
<table border="
Set objConnection = CreateObject("ADODB.Connection")
Set objRecordSet = CreateObject("ADODB.Recordset")
strPathtoTextFile = "C:\1\"
objConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & strPathtoTextFile & ";" & _
"Extended Properties=""text;HDR=YES;FMT=Delimited"""
objRecordset.Open "SELECT * FROM ZZ.csv", _
objConnection, adOpenStatic, adLockOptimistic, adCmdText
i=0
'populate the array with information
Do Until objRecordset.EOF
Redim Preserve ArrAll(i)
ArrAll(i) = objRecordset.Fields.Item("NAME")
i=i+1
objRecordset.MoveNext
Loop
objRecordset.Close
'use array to open whatever file and write info
For i = 1 to Ubound(ArrAll)
name1=ArrAll(i) & name2
name3=Ins1 & ArrAll & ins3
Set objFile = objFSO.OpenTextFile(name1, ForReading)
HtmlFile = objFile.ReadAll
objfile.Close
'*****************************************
HtmlFile = Replace(HtmlFile,"</i></h1>
<table border=",name3)
'*****************************************
Set objFile = objFSO.OpenTextFile(name1, ForWriting)
objFile.WriteLine HtmlFile
objFile.Close
Next
Totally new to VBS scripts, my program is not elegant (and its the third attempt). I've searched for the solution for what i want to do - which should seem obvious but ...nothing.
In a nutshell i want to assign something like this
ins3 = ".jpg></A></i></h1><table border="
and be able to do a replace for
HtmlFile = Replace(HtmlFile,"</i></h1><table border=",name3)
Purpose is to insert a jpg (or whatever) file in a large (like 7000) number of html files, each of the htmls contains a table - that's where the pic should go.
Thanks in advance
This is the code
On Error Resume Next
Dim ArrAll()
Const adOpenStatic = 3
Const adLockOptimistic = 3
Const adCmdText = &H0001
Const ForReading = 1
Const ForAppending = 8
Const ForWritting = 2
name2 = ".html"
Ins1 = "<IMG SRC ="
'*****************************************
ins3 = ".jpg></A></i></h1>
'*****************************************
<table border="
Set objConnection = CreateObject("ADODB.Connection")
Set objRecordSet = CreateObject("ADODB.Recordset")
strPathtoTextFile = "C:\1\"
objConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & strPathtoTextFile & ";" & _
"Extended Properties=""text;HDR=YES;FMT=Delimited"""
objRecordset.Open "SELECT * FROM ZZ.csv", _
objConnection, adOpenStatic, adLockOptimistic, adCmdText
i=0
'populate the array with information
Do Until objRecordset.EOF
Redim Preserve ArrAll(i)
ArrAll(i) = objRecordset.Fields.Item("NAME")
i=i+1
objRecordset.MoveNext
Loop
objRecordset.Close
'use array to open whatever file and write info
For i = 1 to Ubound(ArrAll)
name1=ArrAll(i) & name2
name3=Ins1 & ArrAll & ins3
Set objFile = objFSO.OpenTextFile(name1, ForReading)
HtmlFile = objFile.ReadAll
objfile.Close
'*****************************************
HtmlFile = Replace(HtmlFile,"</i></h1>
<table border=",name3)
'*****************************************
Set objFile = objFSO.OpenTextFile(name1, ForWriting)
objFile.WriteLine HtmlFile
objFile.Close
Next