Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Automatically move text from one document to another | Excel Worksheet Functions | |||
creating text document | Excel Discussion (Misc queries) | |||
Find repeated text in a text document in Excel | Excel Worksheet Functions | |||
text disappears from document to excel | New Users to Excel | |||
Replace text in an XML document | Excel Programming |