Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #16  
Old 03-03-2024, 03:00 AM
RobiNew RobiNew is offline Remove normal columns and their content in main story range Windows 10 Remove normal columns and their content in main story range Office 2016
Competent Performer
Remove normal columns and their content in main story range
 
Join Date: Sep 2023
Posts: 183
RobiNew is on a distinguished road
Default

Hi, Vivka! Too good to be true. Inserting 'ActiveWindow.View.Type = wdPrintView' before the code in question worked only once or twice. Following your suggestion, I inserted 'rng.Select' before 'rng.Delete' and saw that the whole doc was selected. How would you reset 'rng'? Thanks a lot!
Reply With Quote
  #17  
Old 03-03-2024, 03:28 AM
Guessed's Avatar
Guessed Guessed is offline Remove normal columns and their content in main story range Windows 10 Remove normal columns and their content in main story range Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,977
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

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
The shorter way to specify your key line and rely ONLY on the default order of parameters is to include extra commas to skip an optional parameter
Set rng = ActiveDocument.Range.GoTo(wdGoToPage, , PgNum)
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia

Last edited by Guessed; 03-03-2024 at 03:29 PM.
Reply With Quote
  #18  
Old 03-03-2024, 04:33 AM
RobiNew RobiNew is offline Remove normal columns and their content in main story range Windows 10 Remove normal columns and their content in main story range Office 2016
Competent Performer
Remove normal columns and their content in main story range
 
Join Date: Sep 2023
Posts: 183
RobiNew is on a distinguished road
Default

Thank you, Guessed! I'm really grateful, especially for the explanations. Everything is OK now.
Reply With Quote
Reply



Similar Threads
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
Remove normal columns and their content in main story range Run Script to remove carriage returns on certain columns ryanjohnsond@gmail.com Excel Programming 34 09-03-2014 10:43 PM
Remove normal columns and their content in main story range Normal sort not bringing along other columns Dave Fraser Excel 2 06-06-2014 11:48 AM
Remove normal columns and their content in main story range Using range object to work with multiple columns kjworduser Word VBA 1 11-01-2013 03:03 AM
Remove normal columns and their content in main story range How to remove blank rows from a specified range? Learner7 Excel 1 04-19-2011 02:45 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:24 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft