Convert Word doc to HTML

C

Chris Davoli

I'm newbie trying to use Office Automation to change a WORD document to an
HTML document for later upload to a web site. When I try to instantiate word
I get the error "Access is denied." What am I doing wrong?

I added Microsoft.Office.Core to my references. I Think its an interop
component. Do I need to do something extra with interop compoonents?

Any simple easy automation articles out there that converts WORD to HTML?

Here is my code:
Dim a As Word.Application
Dim c As Word.Document
Dim sf, df As String
Try
'Get valid file name
df = "c:\UploadTest\Herring Memo Holidays.doc"
sf = "c:\UploadTest\kk.html"
a = New Word.Application
c = a.Documents.Open(df)
c.Fields.Unlink()
c.SaveAs(sf, Word.WdSaveFormat.wdFormatHTML) 'save the doc file
as HTML
c.Close()
c = Nothing
a.Quit()
a = Nothing
'MsgBox("Converted successfully")
Catch ex As Exception
Response.Write(ex.StackTrace)
'MsgBox(ex.StackTrace)
End Try
 
J

Jonathan West

2 possible problems occur to me

1. You need to set a reference to Word object library in addition to the
office object library

2. This line looks a bit odd.

c.SaveAs(sf, Word.WdSaveFormat.wdFormatHTML) 'save the doc file as HTML

Shouldn't it be this?

c.SaveAs(sf, a.WdSaveFormat.wdFormatHTML) 'save the doc file as HTML

--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 
C

Chris Davoli

Thanks tried that but still get error. The error is on the line where I'm
instantiating word.
ie; a = New Word.Application

What else can I try to instantiate WORD?
--
Chris Davoli



Jonathan West said:
2 possible problems occur to me

1. You need to set a reference to Word object library in addition to the
office object library

2. This line looks a bit odd.

c.SaveAs(sf, Word.WdSaveFormat.wdFormatHTML) 'save the doc file as HTML

Shouldn't it be this?

c.SaveAs(sf, a.WdSaveFormat.wdFormatHTML) 'save the doc file as HTML

--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 
C

Chris Davoli

Johnathain, like I said I'm a newbie so is there an article out there that
shows how to do office automation to convert word doc to HTML?

Don't know what you mean in point #1.
--
Chris Davoli



Chris Davoli said:
Thanks tried that but still get error. The error is on the line where I'm
instantiating word.
ie; a = New Word.Application

What else can I try to instantiate WORD?
 
J

Jonathan West

Chris Davoli said:
Johnathain, like I said I'm a newbie so is there an article out there that
shows how to do office automation to convert word doc to HTML?

Don't know what you mean in point #1.

I don't use VB.NET so I don't know the precise mechnism for set a reference
to an external ActiveX object, but this is what you need to do. I'm sure
someone in one of the VB.NET groups will be able to help with that.

Apart from that, there is nothing obviously wrong with your code - you
definitely seem to be working along the right lines.
 

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