dscheste
Board Regular
- Joined
- Jul 10, 2004
- Messages
- 206
Hello guys,
I decided to export a knowledge database. The FAQ is running on PHPMyFAQ.
I decided to create a html file and with xmlhttp parse the topic and the FAQ, surrond it with some html formatting - and bingo.
Thought I.
Excel does it perferctly, all the faqs land in the worksheet as I request, providing the running numbers for the question IDs.
When I introduce the Scripting.FileSystemObject and create a text file, the file is created all right but is filled with 5 records only. Then the code throws
Run time error 5 and errors out.
Why is that? Is there a cure? I hoped to have the page like 50 pages, but it just does not want to grow 5 records. If I cut the topics or formatting, it accomodates 6. But that is it.
Please help.
Here is the code:
the variable cell is the ID number of the FAQ
<font face=Courier New><SPAN style="color:#00007F">Sub</SPAN> Get_Me_The_FAQ()
<SPAN style="color:#00007F">With</SPAN> Application
.EnableEvents = <SPAN style="color:#00007F">False</SPAN>
<SPAN style="color:#00007F">Dim</SPAN> fso, tf, xmlhttp, topic, faq, mystart, myend, artikelsize
<SPAN style="color:#00007F">Set</SPAN> fso = CreateObject("Scripting.FileSystemObject")
<SPAN style="color:#00007F">Set</SPAN> tf = fso.CreateTextFile("c:\parsed.html", <SPAN style="color:#00007F">True</SPAN>)
<SPAN style="color:#00007F">Set</SPAN> Rng = Range("B2:B50")
tf.Writeline ("<html><head><title>Parsed from myPHP</title></head><body>")
<SPAN style="color:#00007F">For</SPAN> <SPAN style="color:#00007F">Each</SPAN> cell <SPAN style="color:#00007F">In</SPAN> Rng
<SPAN style="color:#00007F">Set</SPAN> xmlhttp = CreateObject("Microsoft.XMLHTTP")
strURL = "my_working_URL"
xmlhttp.Open "GET", strURL, <SPAN style="color:#00007F">False</SPAN>, "", ""
xmlhttp.Send
rtnpage = xmlhttp.ResponseText
<SPAN style="color:#007F00">'Get the topic</SPAN>
Range("A2").Value = cell.Row
mystart = InStr(rtnpage, "[/i]")
myend = InStr(rtnpage, "</h2>")
artikelsize = myend - mystart
topic = Mid(rtnpage, mystart + 5, artikelsize - 5)
cell.Offset(0, 1).Value = topic
tf.Write ("some html format" & topic & "some html format") <SPAN style="color:#007F00">' Writes the name of the topic</SPAN>
<SPAN style="color:#00007F">Set</SPAN> topic = <SPAN style="color:#00007F">Nothing</SPAN>
<SPAN style="color:#007F00">'Get the topic text</SPAN>
mystart = InStr(rtnpage, "")
myend = InStr(rtnpage, " ")
artikelsize = myend - mystart
faq = Mid(rtnpage, mystart + 22, artikelsize - 21)
cell.Offset(0, 2).Value = faq
<SPAN style="color:#007F00">'MsgBox (faq)</SPAN>
tf.Write ("some html format " & faq & "some html format") <SPAN style="color:#007F00">'writes the actual answer</SPAN>
<SPAN style="color:#00007F">Set</SPAN> faq = <SPAN style="color:#00007F">Nothing</SPAN>
<SPAN style="color:#00007F">Next</SPAN>
.EnableEvents = <SPAN style="color:#00007F">True</SPAN>
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN>
tf.Writeline ("</body></html>")
tf.Close
<SPAN style="color:#00007F">Exit</SPAN> <SPAN style="color:#00007F">Sub</SPAN>
error:
MsgBox ("Error occured")
tf.Writeline ("</body></html>")
tf.Close
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN>
</FONT>
I decided to export a knowledge database. The FAQ is running on PHPMyFAQ.
I decided to create a html file and with xmlhttp parse the topic and the FAQ, surrond it with some html formatting - and bingo.
Thought I.
Excel does it perferctly, all the faqs land in the worksheet as I request, providing the running numbers for the question IDs.
When I introduce the Scripting.FileSystemObject and create a text file, the file is created all right but is filled with 5 records only. Then the code throws
Run time error 5 and errors out.
Why is that? Is there a cure? I hoped to have the page like 50 pages, but it just does not want to grow 5 records. If I cut the topics or formatting, it accomodates 6. But that is it.
Please help.
Here is the code:
the variable cell is the ID number of the FAQ
<font face=Courier New><SPAN style="color:#00007F">Sub</SPAN> Get_Me_The_FAQ()
<SPAN style="color:#00007F">With</SPAN> Application
.EnableEvents = <SPAN style="color:#00007F">False</SPAN>
<SPAN style="color:#00007F">Dim</SPAN> fso, tf, xmlhttp, topic, faq, mystart, myend, artikelsize
<SPAN style="color:#00007F">Set</SPAN> fso = CreateObject("Scripting.FileSystemObject")
<SPAN style="color:#00007F">Set</SPAN> tf = fso.CreateTextFile("c:\parsed.html", <SPAN style="color:#00007F">True</SPAN>)
<SPAN style="color:#00007F">Set</SPAN> Rng = Range("B2:B50")
tf.Writeline ("<html><head><title>Parsed from myPHP</title></head><body>")
<SPAN style="color:#00007F">For</SPAN> <SPAN style="color:#00007F">Each</SPAN> cell <SPAN style="color:#00007F">In</SPAN> Rng
<SPAN style="color:#00007F">Set</SPAN> xmlhttp = CreateObject("Microsoft.XMLHTTP")
strURL = "my_working_URL"
xmlhttp.Open "GET", strURL, <SPAN style="color:#00007F">False</SPAN>, "", ""
xmlhttp.Send
rtnpage = xmlhttp.ResponseText
<SPAN style="color:#007F00">'Get the topic</SPAN>
Range("A2").Value = cell.Row
mystart = InStr(rtnpage, "[/i]")
myend = InStr(rtnpage, "</h2>")
artikelsize = myend - mystart
topic = Mid(rtnpage, mystart + 5, artikelsize - 5)
cell.Offset(0, 1).Value = topic
tf.Write ("some html format" & topic & "some html format") <SPAN style="color:#007F00">' Writes the name of the topic</SPAN>
<SPAN style="color:#00007F">Set</SPAN> topic = <SPAN style="color:#00007F">Nothing</SPAN>
<SPAN style="color:#007F00">'Get the topic text</SPAN>
mystart = InStr(rtnpage, "")
myend = InStr(rtnpage, " ")
artikelsize = myend - mystart
faq = Mid(rtnpage, mystart + 22, artikelsize - 21)
cell.Offset(0, 2).Value = faq
<SPAN style="color:#007F00">'MsgBox (faq)</SPAN>
tf.Write ("some html format " & faq & "some html format") <SPAN style="color:#007F00">'writes the actual answer</SPAN>
<SPAN style="color:#00007F">Set</SPAN> faq = <SPAN style="color:#00007F">Nothing</SPAN>
<SPAN style="color:#00007F">Next</SPAN>
.EnableEvents = <SPAN style="color:#00007F">True</SPAN>
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN>
tf.Writeline ("</body></html>")
tf.Close
<SPAN style="color:#00007F">Exit</SPAN> <SPAN style="color:#00007F">Sub</SPAN>
error:
MsgBox ("Error occured")
tf.Writeline ("</body></html>")
tf.Close
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN>
</FONT>