Trying to Save Only Part of Document to HTML

P

Phil Galey

I'm using the Word 9 object in VB.NET. I have a 2-page document, where the
second page is also a separate section, which contains an image.

I need to save only the first page to an HTML file. I'm trying to do this
by deleting the second section using the following code:

wd.GoTo(Word.WdGoToItem.wdGoToSection, 2)
wd.Content.Delete(Word.WdUnits.wdSection, 1)
wd.SaveAs("<Path for HTM file>", Word.WdSaveFormat.wdFormatHTML)

however, the second line results in a Bad Parameter error. What am I doing
wrong? How can I save only the first page to an HTML file? Thanks.
 
C

Cindy M.

Hi Phil,
I'm using the Word 9 object in VB.NET. I have a 2-page document, where the
second page is also a separate section, which contains an image.

I need to save only the first page to an HTML file. I'm trying to do this
by deleting the second section using the following code:

wd.GoTo(Word.WdGoToItem.wdGoToSection, 2)
wd.Content.Delete(Word.WdUnits.wdSection, 1)
wd.SaveAs("<Path for HTM file>", Word.WdSaveFormat.wdFormatHTML)

however, the second line results in a Bad Parameter error. What am I doing
wrong? How can I save only the first page to an HTML file?
Your approach is good, but try working with ranges, rather than selecting.
Something like this?

wd.Sections(2).Range.Delete

If you're using Option Strict On then you need to pass two parameters. Just
pass Type.Missing (or System.Reflection.Missing.Value) to accept the default
action.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :)
 

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