Boiler Plateing text into another text document.
Geoff E wrote:
On Sep 14, 5:44 pm, keiji kounoike <"kounoike A | T ma.Pikara.ne.jp"
wrote:
Hi Keiji.
The "htm" file that is scripted by this routine contains a table with
only two rows.
In the original routine the first row was closed after each pass of
the loop but new rows were not opened each time that this was done.
But I now have it working perfectly, thanks to your assistance. I have
also made the code a little more clearer and it now looks like this:
Public Sub importBoilerPlate()
Dim strng, trgt, imprt As String
On Error GoTo err_handler
ActiveWorkbook.Save
'================================================= ==================
trgt = ActiveSheet.Range("E4")
imprt = ActiveSheet.Range("F4")
Open trgt For Output As #1
Print #1, "<html<body<center<h2Heading</h2"
Print #1, "Standard generated text - not imported "
Print #1, "<table<tr<td"
Open imprt For Input As #2
Do While Not EOF(2)
Line Input #2, strng
Print #1, strng
Loop
Close #2
Print #1, "<br0942</td</tr</table</center</body</html"
Close #1
'================================================= ====================
Exit Sub
err_handler:
MsgBox Err.Number & vbCrLf & Err.Description
Close #1
Close #2
End Sub
When I find the time, in the next few days, I will be looking at
getting it to loop through a whole series of pages instead of the
single one that it now does.
Rgds
Geoff
Hi Geoff
I can't get what to loop through a whole series of pages, so this could
be a quite diffrernt one from what you are looking for. but give it a try.
Public Sub importBoilerPlate_Test()
Dim strng As String, trgt As String, imprt As String
Dim tmp As String, tmpimprt As String
Dim n As Long
Dim arr
On Error GoTo err_handler
ActiveWorkbook.Save
imprt = ActiveSheet.Range("E4")
trgt = ActiveSheet.Range("F4")
If Dir(trgt) = "" Then
Open trgt For Output As #1
Open imprt For Input As #2
Print #1, "<html<body<center<h2Heading</h2"
Print #1, "Standard generated text - not imported "
Print #1, "<table"
Else
arr = Split(trgt, "\")
arr(UBound(arr)) = "Tmp_" & arr(UBound(arr))
tmpimprt = Join(arr, "\")
Open tmpimprt For Output As #1
Open trgt For Input As #2
Do While Not EOF(2)
Line Input #2, strng
n = InStr(strng, "</table")
If n = 0 Then
Print #1, strng
ElseIf Left(strng, n - 1) < "" Then
Print #1, Left(strng, n - 1)
Exit Do
Else
Exit Do
End If
Loop
Close #1
Close #2
Kill trgt
Name tmpimprt As trgt
Open trgt For Append As #1
Open imprt For Input As #2
End If
strng = ""
Do While Not EOF(2)
tmp = Input(1, #2)
If tmp = Chr(10) And strng < "" Then
Print #1, "<tr<td"
Print #1, strng
Print #1, "</td</tr"
strng = ""
ElseIf tmp = Chr(13) And strng < "" Then
Print #1, "<tr<td"
Print #1, strng
Print #1, "</td</tr"
strng = ""
Else
strng = strng & tmp
End If
Loop
Print #1, "</table</center</body</html"
Close #1
Close #2
Exit Sub
err_handler:
MsgBox Err.Number & vbCrLf & Err.Description
Close #1
Close #2
End Sub
Keiji
|