![]() |
#14
|
||||
|
||||
![]()
I think there are two problems with your code
1. the PgNum should be an integer, not a string 2. You need to be explicit with the variables you are passing to the GoTo command as Word is not thinking you are asking for a page number. All the variables are optional and Word is expecting them in the following order. expression.GoTo( What , Which , Count , Name ) From your code, you were passing the page number in as a string which Word thought was for the optional "Which" parameter and it appears it was intended to be the "Count" parameter. If you haven't explicitly named the parameter for each variable Word tries to align the variables in the same order as the intellisense (and help file) displays the parameters Try it again with these variations... Code:
Sub DeleteFromPgToEnd() 'Delete pages from PgNum till the doc's end. Dim rng As Range Dim PgNum As Integer PgNum = CInt(InputBox("Enter the number of the page")) Set rng = ActiveDocument.Range.GoTo(What:=wdGoToPage, Count:=PgNum) rng.End = ActiveDocument.Range.End 'rng.Select 'enable for testing 'If there's a page break before the PgNum page, the pages won't get 'deleted, so move the rng's start: If rng.Characters.First.Previous = Chr(12) Then rng.Start = rng.Start - 1 End If 'rng.Select 'enable for testing rng.Delete End Sub Set rng = ActiveDocument.Range.GoTo(wdGoToPage, , PgNum)
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia Last edited by Guessed; 03-03-2024 at 03:29 PM. |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Use a table in appendix to determine content of main document? | MattMurray | Word | 3 | 07-19-2022 09:16 AM |
![]() |
ryanjohnsond@gmail.com | Excel Programming | 34 | 09-03-2014 10:43 PM |
![]() |
Dave Fraser | Excel | 2 | 06-06-2014 11:48 AM |
![]() |
kjworduser | Word VBA | 1 | 11-01-2013 03:03 AM |
![]() |
Learner7 | Excel | 1 | 04-19-2011 02:45 AM |