how can i convert a word(contain table) to a HTML file, using VB

  • Thread starter xiaohai wang via OfficeKB.com
  • Start date
X

xiaohai wang via OfficeKB.com

hello,
i'm a newer in VB.
could any boddy tell me how can i convert an exising word file to a HTML
file,using VB.
Attention please, not only SaveAs to HTML simply.
now i can covert a .doc file to HTML file when it contain characters
entirely. the following code cloud do it(portion).
But i can't convert the .doc file to HTML when it contain table.
if somebody can help me,thank you very much!




*******************************************************************
(portion)
Dim objWordApp As New Word.Application
Dim objDoc As Word.Document
Set objWordApp = CreateObject("Word.Application")
Set objDoc = objWordApp.Documents.Open("mydoc3.doc", , , , , , False)
Dim objP As word.Paragraphs
Set objP = objDoc.Paragraphs
Dim intCnt As Integer
Dim strPr As String
For intCnt = 1 To objP.Count
strPr = objP.Item(intCnt).Range.Text
Open "tel.html" For Append As #1
head$ = "<html><head><title>hello</title></head><body><center>"
theTable$ = "<table border=0 width=70%><tr bgcolor= >"
items$ = "<td align=left>&nbsp;&nbsp;&nbsp;&nbsp;"& strPr & "</td>"
items2$ = "</tr>"
theEnd$ = "</table></center></body></html>"
Print #1, head$, theTable$, items$, items2$, theEnd$
Close #1
Next inCnt
*************************************************************
 
C

Chuck

Sorry I can't help very much as I don't know HTML. However, a couple of
observations:

You should start your modules with "Option Explicit". This will force you
to declare all your variables explicitly which helps track down certain bugs.
For instance, I note that your For...Next code contains an error ("Next
inCnt" should be "Next intCnt").

When I ran your code (after declaring all variables explicitly) the code
seems to convert the table to text in the sense that each cell becomes the
equivalent of a separate paragraph. This may be because you're looping
through every paragraph in the document, rather than looping through each
cell in the table?

I would think that you'd need to go through each column/row in each table,
get dimensions then recreate the table in HTML, which is a more complicated
procedure than converting paragraphs.

Unless someone else has a better idea, you could explore how to recreate the
Word tables in HTML by saving the document as HTML, then studying the source
for the HTML to see how Word automatically converted the table and then using
those principles in your code.

Sorry I can't be of more help. Hopefully someone else will be able to give
you better advice.
 
X

xiaohai wang via OfficeKB.com

??,Hi,Chuck, thank you all the same!
you are a warmheated men, it's feel wonderful.
we become nearly throuth the internet,now i am in beijing China.:)
 
C

Chuck

You're very welcome xioahai. I thought you might be in China (from your
name). I'm located in Dublin Ireland.

Have you posted your question in the FrontPage forum (Developer-Office
Solutions.FrontPage.Programming)? They might have some ideas for you...

Good luck!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top