Problems programmatically delete pages in a word document

S

Stefan Haag

Hi

I'm using VBA to programmatically delete pages from a word document. The
original document is a word template and by using a form I'm choosing which
pages that should be deleted.

I'm using word2000 and everything works fine. I have also tested on
different computer using word2003.On some of thease computers everything
works fine but on some other computers the program crashes and i get the
following error message: "Run-time-Error '4608'. Value out of range".

Why is it working on some computers but dont work on other computers when
the same version of word is beeing used?



Here is the code row where the program crashes:
ActiveDocument.Range(lngStart, lngEnd).Delete

The code row is used in the following Sub:

Private Sub ShowLogo()
Dim lngStart As Long
Dim lngEnd As Long

If optionbutton60.Value = True Then
ActiveDocument.Tables(1).Delete
ActiveDocument.Tables(2).Delete
'remove pages
lngStart = ActiveDocument.Range.GoTo(wdGoToPage, wdGoToAbsolute,
1).Start
lngEnd = ActiveDocument.Range.GoTo(wdGoToPage, wdGoToAbsolute,
2).Start
ActiveDocument.Range(lngStart, lngEnd).Delete

lngStart = ActiveDocument.Range.GoTo(wdGoToPage, wdGoToAbsolute,
2).Start - 1
lngEnd = ActiveDocument.Range.GoTo(wdGoToPage, wdGoToAbsolute,
2).End
ActiveDocument.Range(lngStart, lngEnd).Delete

End If

End Sub


With regards
Stefan
 
C

Cindy M -WordMVP-

Hi Stefan,
I'm using VBA to programmatically delete pages from a word document. The
original document is a word template and by using a form I'm choosing which
pages that should be deleted.

I'm using word2000 and everything works fine. I have also tested on
different computer using word2003.On some of thease computers everything
works fine but on some other computers the program crashes and i get the
following error message: "Run-time-Error '4608'. Value out of range".

Why is it working on some computers but dont work on other computers when
the same version of word is beeing used?
Impossible to even begin to guess without seeing the code, and knowing the
line which is causing the error.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
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