Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Boiler Plateing text into another text document.

I am trying to import the content of a ".txt" file into a formatted
web page. I seem to have a good grasp on the writeing part but not the
reading (importing) part.

The following is where I am at at the moment:

Public Sub importBoilerPlate()
Dim i As Long
Dim streng As String
On Error GoTo err_handler
ActiveWorkbook.Save
'================================================= ==================
Myfile = "H:\Tam\importBoPl.htm"
Open Myfile For Output As #1
Print #1, "<html<body<center<h2Heading</h2"
Print #1, "Standard generated text - not imported "
Print #1, "<table<tr<td"
MyBoilerPlate = "H:\Tam\testText.txt"
Open MyBoilerPlate For Output As #2
i = 0
Do While Not EOF(1)
Line Input #2, streng {I suspect my problem lays on this line}
i = i + 1
Loop
Close #2
Print #1, "</td</tr<tr<td"
Print #1, "Saturday 12th September 0942hrs"
Print #1, "</td</tr</table</center</body</html"
Close #1
'================================================= ====================
Exit Sub
err_handler:
MsgBox Err.Number & vbCrLf & Err.Description
End Sub


This is what is produced:

<html<body<center<h2Heading</h2
Standard generated text - not imported
<table<tr<td
{Note: The imported text should appear in here.}
</td</tr<tr<td
Saturday 12th September 0942hrs
</td</tr</table</center</body</html

Your comments, suggestions and assistance would be greatly
appreciated.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 199
Default Boiler Plateing text into another text document.

I don't know what "H:\Tam\testText.txt" is and how you like to have your
"importBoPl.htm" look. I guessed this is what you are looking for but
I'm not sure.

Public Sub importBoilerPlate()
Dim i As Long
Dim streng As String
On Error GoTo err_handler
ActiveWorkbook.Save
'================================================= ==================
Myfile = "H:\Tam\testText.txt"
Open Myfile For Output As #1
Print #1, "<html<body<center<h2Heading</h2"
Print #1, "Standard generated text - not imported "
Print #1, "<table"
MyBoilerPlate = "H:\Tam\testText.txt"
Open MyBoilerPlate For Input As #2
i = 0
Do While Not EOF(2)
Line Input #2, streng
Print #1, "<tr<td"
Print #1, streng
Print #1, "</td</tr"
Loop
Close #2
Print #1, "<tr<td"
Print #1, "Saturday 12th September 0942hrs"
Print #1, "</td</tr</table</center</body</html"
Close #1
'================================================= ====================
Exit Sub
err_handler:
MsgBox Err.Number & vbCrLf & Err.Description
Close #1
Close #2
End Sub

Keiji

Geoff E wrote:
I am trying to import the content of a ".txt" file into a formatted
web page. I seem to have a good grasp on the writeing part but not the
reading (importing) part.

The following is where I am at at the moment:

Public Sub importBoilerPlate()
Dim i As Long
Dim streng As String
On Error GoTo err_handler
ActiveWorkbook.Save
'================================================= ==================
Myfile = "H:\Tam\importBoPl.htm"
Open Myfile For Output As #1
Print #1, "<html<body<center<h2Heading</h2"
Print #1, "Standard generated text - not imported "
Print #1, "<table<tr<td"
MyBoilerPlate = "H:\Tam\testText.txt"
Open MyBoilerPlate For Output As #2
i = 0
Do While Not EOF(1)
Line Input #2, streng {I suspect my problem lays on this line}
i = i + 1
Loop
Close #2
Print #1, "</td</tr<tr<td"
Print #1, "Saturday 12th September 0942hrs"
Print #1, "</td</tr</table</center</body</html"
Close #1
'================================================= ====================
Exit Sub
err_handler:
MsgBox Err.Number & vbCrLf & Err.Description
End Sub


This is what is produced:

<html<body<center<h2Heading</h2
Standard generated text - not imported
<table<tr<td
{Note: The imported text should appear in here.}
</td</tr<tr<td
Saturday 12th September 0942hrs
</td</tr</table</center</body</html

Your comments, suggestions and assistance would be greatly
appreciated.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Boiler Plateing text into another text document.

On Sep 14, 12:47*pm, keiji kounoike <"kounoike A | T
ma.Pikara.ne.jp" wrote:
I don't know what "H:\Tam\testText.txt" is and how you like to have your
"importBoPl.htm" look. I guessed this is what you are looking for but
I'm not sure.

Public Sub importBoilerPlate()
Dim i As Long
Dim streng As String
On Error GoTo err_handler
ActiveWorkbook.Save
'================================================= ==================
Myfile = "H:\Tam\testText.txt"
Open Myfile For Output As #1
Print #1, "<html<body<center<h2Heading</h2"
Print #1, "Standard generated text - not imported "
Print #1, "<table"
MyBoilerPlate = "H:\Tam\testText.txt"
Open MyBoilerPlate For Input As #2
i = 0
Do While Not EOF(2)
Line Input #2, streng
Print #1, "<tr<td"
Print #1, streng
Print #1, "</td</tr"
Loop
Close #2
Print #1, "<tr<td"
Print #1, "Saturday 12th September 0942hrs"
Print #1, "</td</tr</table</center</body</html"
Close #1
'================================================= ====================
Exit Sub
err_handler:
MsgBox Err.Number & vbCrLf & Err.Description
Close #1
Close #2
End Sub

Keiji



Geoff E wrote:
I am trying to import the content of a ".txt" file into a formatted
web page. I seem to have a good grasp on the writeing part but not the
reading (importing) part.


The following is where I am at at the moment:


Public Sub importBoilerPlate()
Dim i As Long
Dim streng As String
On Error GoTo err_handler
ActiveWorkbook.Save
'================================================= ==================
Myfile = "H:\Tam\importBoPl.htm"
Open Myfile For Output As #1
Print #1, "<html<body<center<h2Heading</h2"
Print #1, "Standard generated text - not imported "
Print #1, "<table<tr<td"
MyBoilerPlate = "H:\Tam\testText.txt"
Open MyBoilerPlate For Output As #2
i = 0
Do While Not EOF(1)
Line Input #2, streng * *{I suspect my problem lays on this line}
i = i + 1
Loop
Close #2
Print #1, "</td</tr<tr<td"
Print #1, "Saturday 12th September 0942hrs"
Print #1, "</td</tr</table</center</body</html"
Close #1
'================================================= ====================
Exit Sub
err_handler:
MsgBox Err.Number & vbCrLf & Err.Description
End Sub


This is what is produced:


<html<body<center<h2Heading</h2
Standard generated text - not imported
<table<tr<td
{Note: *The imported text should appear in here.}
</td</tr<tr<td
Saturday 12th September 0942hrs
</td</tr</table</center</body</html


Your comments, suggestions and assistance would be greatly
appreciated.- Hide quoted text -


- Show quoted text -



Keiji... Thank you for your reply

"H:\Tam\testText.txt" is the path to the file that contains the text
to be imported. That text is in the form of a collection of
paragraphs, much like that which you would expect to see in a letter.
It does not contain delimited data which would be subjected to further
processing.

"H:\" is the identity of a flash drive which I am using for testing
purposes.

"importBoPl.htm" Is the name of the destination file which is the
script for a web page.

I actually tried your routine but, unfortunately, it did not
work.However, there was some very useful information on there so I
adjusted my routine to reflect what I learnt from yours. It still does
not work, but it now looks like this:


Public Sub importBoilerPlate()
Dim i As Long
Dim streng As String
On Error GoTo err_handler
ActiveWorkbook.Save
'================================================= ==================
Myfile = "H:\MsTamsin\importBoPl.htm"
Open Myfile For Output As #1
Print #1, "<html<body<center<h2Page Heading</h2"
Print #1, "Standard generated text - not imported "
Print #1, "<table<tr<td"
MyBoilerPlate = "H:\MsTamsin\testText.txt"
Open MyBoilerPlate For Output As #2
i = 0
Do While Not EOF(2)
Line Input #2, streng
Print #1, "streng"
i = i + 1
Loop
Close #2
Print #1, "</td</tr<tr<td"
Print #1, "Monday 14th September 1327 hrs"
Print #1, "</td</tr</table</center</body</html"
Close #1
'================================================= ====================
Exit Sub
err_handler:
MsgBox Err.Number & vbCrLf & Err.Description
End Sub

Looking forward to further assistance on this matter.
Geoff E


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 199
Default Boiler Plateing text into another text document.

Geoff E wrote:
On Sep 14, 12:47 pm, keiji kounoike <"kounoike A | T
ma.Pikara.ne.jp" wrote:
I don't know what "H:\Tam\testText.txt" is and how you like to have your
"importBoPl.htm" look. I guessed this is what you are looking for but
I'm not sure.



Keiji... Thank you for your reply

"H:\Tam\testText.txt" is the path to the file that contains the text
to be imported. That text is in the form of a collection of
paragraphs, much like that which you would expect to see in a letter.
It does not contain delimited data which would be subjected to further
processing.

"H:\" is the identity of a flash drive which I am using for testing
purposes.

"importBoPl.htm" Is the name of the destination file which is the
script for a web page.

I actually tried your routine but, unfortunately, it did not
work.However, there was some very useful information on there so I
adjusted my routine to reflect what I learnt from yours. It still does
not work, but it now looks like this:


Public Sub importBoilerPlate()
Dim i As Long
Dim streng As String
On Error GoTo err_handler
ActiveWorkbook.Save
'================================================= ==================
Myfile = "H:\MsTamsin\importBoPl.htm"
Open Myfile For Output As #1
Print #1, "<html<body<center<h2Page Heading</h2"
Print #1, "Standard generated text - not imported "
Print #1, "<table<tr<td"
MyBoilerPlate = "H:\MsTamsin\testText.txt"
Open MyBoilerPlate For Output As #2
i = 0
Do While Not EOF(2)
Line Input #2, streng
Print #1, "streng"
i = i + 1
Loop
Close #2
Print #1, "</td</tr<tr<td"
Print #1, "Monday 14th September 1327 hrs"
Print #1, "</td</tr</table</center</body</html"
Close #1
'================================================= ====================
Exit Sub
err_handler:
MsgBox Err.Number & vbCrLf & Err.Description
End Sub

Looking forward to further assistance on this matter.
Geoff E


If you don't mind, let me know how did my code not work.
Anyway, I think the line Print #1, "streng" in your code above should be

Print #1, streng

("" should not be added)

In your code, Print #1, "streng" will write the string "Strng" itself
into the importBoPl.htm file.

I think you should put Close #1 and Close #2 in error handle. if not, if
error ocuurs, then you can't open your files next time.

P.S I wonder what the variable i means?

Keiji

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 199
Default Boiler Plateing text into another text document.

keiji kounoike wrote:
Geoff E wrote:
On Sep 14, 12:47 pm, keiji kounoike <"kounoike A | T
ma.Pikara.ne.jp" wrote:
I don't know what "H:\Tam\testText.txt" is and how you like to have your
"importBoPl.htm" look. I guessed this is what you are looking for but
I'm not sure.



Keiji... Thank you for your reply

"H:\Tam\testText.txt" is the path to the file that contains the text
to be imported. That text is in the form of a collection of
paragraphs, much like that which you would expect to see in a letter.
It does not contain delimited data which would be subjected to further
processing.

"H:\" is the identity of a flash drive which I am using for testing
purposes.

"importBoPl.htm" Is the name of the destination file which is the
script for a web page.

I actually tried your routine but, unfortunately, it did not
work.However, there was some very useful information on there so I
adjusted my routine to reflect what I learnt from yours. It still does
not work, but it now looks like this:


Public Sub importBoilerPlate()
Dim i As Long
Dim streng As String
On Error GoTo err_handler
ActiveWorkbook.Save
'================================================= ==================
Myfile = "H:\MsTamsin\importBoPl.htm"
Open Myfile For Output As #1
Print #1, "<html<body<center<h2Page Heading</h2"
Print #1, "Standard generated text - not imported "
Print #1, "<table<tr<td"
MyBoilerPlate = "H:\MsTamsin\testText.txt"
Open MyBoilerPlate For Output As #2
i = 0
Do While Not EOF(2)
Line Input #2, streng
Print #1, "streng"
i = i + 1
Loop
Close #2
Print #1, "</td</tr<tr<td"
Print #1, "Monday 14th September 1327 hrs"
Print #1, "</td</tr</table</center</body</html"
Close #1
'================================================= ====================
Exit Sub
err_handler:
MsgBox Err.Number & vbCrLf & Err.Description
End Sub

Looking forward to further assistance on this matter.
Geoff E


If you don't mind, let me know how did my code not work.
Anyway, I think the line Print #1, "streng" in your code above should be

Print #1, streng

("" should not be added)

In your code, Print #1, "streng" will write the string "Strng" itself
into the importBoPl.htm file.

I think you should put Close #1 and Close #2 in error handle. if not, if
error ocuurs, then you can't open your files next time.

P.S I wonder what the variable i means?

Keiji



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 199
Default Boiler Plateing text into another text document.

keiji kounoike wrote:
Geoff E wrote:
On Sep 14, 12:47 pm, keiji kounoike <"kounoike A | T
ma.Pikara.ne.jp" wrote:
I don't know what "H:\Tam\testText.txt" is and how you like to have your
"importBoPl.htm" look. I guessed this is what you are looking for but
I'm not sure.



Keiji... Thank you for your reply

"H:\Tam\testText.txt" is the path to the file that contains the text
to be imported. That text is in the form of a collection of
paragraphs, much like that which you would expect to see in a letter.
It does not contain delimited data which would be subjected to further
processing.

"H:\" is the identity of a flash drive which I am using for testing
purposes.

"importBoPl.htm" Is the name of the destination file which is the
script for a web page.

I actually tried your routine but, unfortunately, it did not
work.However, there was some very useful information on there so I
adjusted my routine to reflect what I learnt from yours. It still does
not work, but it now looks like this:


Public Sub importBoilerPlate()
Dim i As Long
Dim streng As String
On Error GoTo err_handler
ActiveWorkbook.Save
'================================================= ==================
Myfile = "H:\MsTamsin\importBoPl.htm"
Open Myfile For Output As #1
Print #1, "<html<body<center<h2Page Heading</h2"
Print #1, "Standard generated text - not imported "
Print #1, "<table<tr<td"
MyBoilerPlate = "H:\MsTamsin\testText.txt"
Open MyBoilerPlate For Output As #2
i = 0
Do While Not EOF(2)
Line Input #2, streng
Print #1, "streng"
i = i + 1
Loop
Close #2
Print #1, "</td</tr<tr<td"
Print #1, "Monday 14th September 1327 hrs"
Print #1, "</td</tr</table</center</body</html"
Close #1
'================================================= ====================
Exit Sub
err_handler:
MsgBox Err.Number & vbCrLf & Err.Description
End Sub

Looking forward to further assistance on this matter.
Geoff E


If you don't mind, let me know how did my code not work.
Anyway, I think the line Print #1, "streng" in your code above should be

Print #1, streng

("" should not be added)

In your code, Print #1, "streng" will write the string "Strng" itself
into the importBoPl.htm file.

I think you should put Close #1 and Close #2 in error handle. if not, if
error ocuurs, then you can't open your files next time.

P.S I wonder what the variable i means?

Keiji


I forgot to mention one more thing.
you opened MyBoilerPlate with output mode, but this should be opened as
input mode. so, your

Open MyBoilerPlate For Output As #2

should be

Open MyBoilerPlate For Input As #2

I made a mistake in my code that Myfile and MyBoilerPlate point to the
same file "H:\Tam\testText.txt". As the result, My code would not work
correctly.

Keiji
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Boiler Plateing text into another text document.

On Sep 14, 3:14*pm, keiji kounoike <"kounoike A | T ma.Pikara.ne.jp"
wrote:
keiji kounoike wrote:
Geoff E wrote:
On Sep 14, 12:47 pm, keiji kounoike <"kounoike A | T
ma.Pikara.ne.jp" wrote:
I don't know what "H:\Tam\testText.txt" is and how you like to have your
"importBoPl.htm" look. I guessed this is what you are looking for but
I'm not sure.


Keiji... Thank you for your reply


"H:\Tam\testText.txt" is the path to the file that contains the text
to be imported. That text is in the form of a collection of
paragraphs, much like that which you would expect to see in a letter.
It does not contain delimited data which would be subjected to further
processing.


"H:\" is the identity of a flash drive which I am using for testing
purposes.


"importBoPl.htm" Is the name of the destination file which is the
script for a web page.


I actually tried your routine but, unfortunately, it did not
work.However, there was some very useful information on there so I
adjusted my routine to reflect what I learnt from yours. It still does
not work, but it now looks like this:


Public Sub importBoilerPlate()
Dim i As Long
Dim streng As String
On Error GoTo err_handler
ActiveWorkbook.Save
'================================================= ==================
Myfile = "H:\MsTamsin\importBoPl.htm"
Open Myfile For Output As #1
Print #1, "<html<body<center<h2Page Heading</h2"
Print #1, "Standard generated text - not imported "
Print #1, "<table<tr<td"
MyBoilerPlate = "H:\MsTamsin\testText.txt"
Open MyBoilerPlate For Output As #2
i = 0
Do While Not EOF(2)
Line Input #2, streng
Print #1, "streng"
i = i + 1
Loop
Close #2
Print #1, "</td</tr<tr<td"
Print #1, "Monday 14th September 1327 hrs"
Print #1, "</td</tr</table</center</body</html"
Close #1
'================================================= ====================
Exit Sub
err_handler:
MsgBox Err.Number & vbCrLf & Err.Description
End Sub


Looking forward to further assistance on this matter.
Geoff E


If you don't mind, let me know how did my code not work.
Anyway, I think the line Print #1, "streng" in your code above should be


Print #1, streng


("" should not be added)


In your code, Print #1, "streng" will write the string "Strng" itself
into the importBoPl.htm file.


I think you should put Close #1 and Close #2 in error handle. if not, if
error ocuurs, then you can't open your files next time.


P.S I wonder what the variable i means?


Keiji


I forgot to mention one more thing.
you opened MyBoilerPlate with output mode, but this should be opened as
input mode. so, your

Open MyBoilerPlate For Output As #2

should be

Open MyBoilerPlate For Input As #2

I made a mistake in my code that Myfile and MyBoilerPlate point to the
same file "H:\Tam\testText.txt". As the result, My code would not work
correctly.

Keiji- Hide quoted text -

- Show quoted text -


Again... thank you Keiji.

I now have it working just fine. This is what I ran with.

Public Sub importBoilerPlate()
Dim i As Long
Dim streng As String
On Error GoTo err_handler
ActiveWorkbook.Save
'================================================= ==================
Myfile = "H:\Tam\importBoPl.htm"
Open Myfile For Output As #1
Print #1, "<html<body<center<h2Heading</h2"
Print #1, "Standard generated text - not imported "
Print #1, "<table<tr<td"
MyBoilerPlate = "H:\Tam\testText.txt"
Open MyBoilerPlate For Input As #2
i = 0
Do While Not EOF(2)
Line Input #2, streng
Print #1, streng
Loop
Close #2
Print #1, "</td</tr"
Print #1, "<tr<td"
Print #1, "Saturday 12th September 1633 hrs"
Print #1, "</td</tr</table</center</body</html"
Close #1
'================================================= ====================
Exit Sub
err_handler:
MsgBox Err.Number & vbCrLf & Err.Description
Close #1
Close #2
End Sub

I think you nailed all the issues I had with your origional, but there
was one other one:

The "<tr<td" and "</td</tr" strings were somehow in the wrong
place and/or duplicated.
While the code may have been working the resulting "HTM" file would
not render.

Regards
Geoff
  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 199
Default Boiler Plateing text into another text document.

Geoff E wrote:
On Sep 14, 3:14 pm, keiji kounoike <"kounoike A | T ma.Pikara.ne.jp"
wrote:



I now have it working just fine. This is what I ran with.

Public Sub importBoilerPlate()
Dim i As Long
Dim streng As String
On Error GoTo err_handler
ActiveWorkbook.Save
'================================================= ==================
Myfile = "H:\Tam\importBoPl.htm"
Open Myfile For Output As #1
Print #1, "<html<body<center<h2Heading</h2"
Print #1, "Standard generated text - not imported "
Print #1, "<table<tr<td"
MyBoilerPlate = "H:\Tam\testText.txt"
Open MyBoilerPlate For Input As #2
i = 0
Do While Not EOF(2)
Line Input #2, streng
Print #1, streng
Loop
Close #2
Print #1, "</td</tr"
Print #1, "<tr<td"
Print #1, "Saturday 12th September 1633 hrs"
Print #1, "</td</tr</table</center</body</html"
Close #1
'================================================= ====================
Exit Sub
err_handler:
MsgBox Err.Number & vbCrLf & Err.Description
Close #1
Close #2
End Sub

I think you nailed all the issues I had with your origional, but there
was one other one:

The "<tr<td" and "</td</tr" strings were somehow in the wrong
place and/or duplicated.
While the code may have been working the resulting "HTM" file would
not render.

Regards
Geoff


Hi Geoff

I can't get it what you said -the resulting "HTM" file would not render.
Do you mean the file produced is not considered as "htm" file? Is it
your code above or my original code that the "<tr<td" and "</td</tr"
strings are in the wrong place and/or duplicated.
Anyway, How do want your file look like?

Keiji
  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Boiler Plateing text into another text document.

On Sep 14, 5:44*pm, keiji kounoike <"kounoike A | T ma.Pikara.ne.jp"
wrote:
Geoff E wrote:
On Sep 14, 3:14 pm, keiji kounoike <"kounoike A | T *ma.Pikara.ne.jp"
wrote:


I now have it working just fine. This is what I ran with.


Public Sub importBoilerPlate()
Dim i As Long
Dim streng As String
On Error GoTo err_handler
ActiveWorkbook.Save
'================================================= ==================
Myfile = "H:\Tam\importBoPl.htm"
Open Myfile For Output As #1
Print #1, "<html<body<center<h2Heading</h2"
Print #1, "Standard generated text - not imported "
Print #1, "<table<tr<td"
MyBoilerPlate = "H:\Tam\testText.txt"
Open MyBoilerPlate For Input As #2
i = 0
Do While Not EOF(2)
Line Input #2, streng
Print #1, streng
Loop
Close #2
Print #1, "</td</tr"
Print #1, "<tr<td"
Print #1, "Saturday 12th September 1633 hrs"
Print #1, "</td</tr</table</center</body</html"
Close #1
'================================================= ====================
Exit Sub
err_handler:
MsgBox Err.Number & vbCrLf & Err.Description
Close #1
Close #2
End Sub


I think you nailed all the issues I had with your origional, but there
was one other one:


The "<tr<td" and "</td</tr" strings were somehow in the wrong
place and/or duplicated.
While the code may have been working the resulting "HTM" file would
not render.


Regards
Geoff


Hi Geoff

I can't get it what you said -the resulting "HTM" file would not render.
* Do you mean the file produced is not considered as "htm" file? Is it
your code above or my original code that the "<tr<td" and "</td</tr"
strings are in the wrong place and/or duplicated.
Anyway, How do want your file look like?

Keiji- Hide quoted text -

- Show quoted text -


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


  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 199
Default 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
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Automatically move text from one document to another BB Excel Worksheet Functions 1 September 22nd 09 07:02 PM
creating text document AJB Excel Discussion (Misc queries) 3 October 30th 08 03:27 PM
Find repeated text in a text document in Excel JE Excel Worksheet Functions 2 June 8th 08 09:32 PM
text disappears from document to excel gregp22 New Users to Excel 1 March 20th 06 04:51 PM
Replace text in an XML document [email protected] Excel Programming 0 May 16th 05 10:38 PM


All times are GMT +1. The time now is 03:52 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"