Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 08-17-2022, 08:18 PM
karlkras karlkras is offline Sanity check on a macro requirement. Windows 10 Sanity check on a macro requirement. Office 2019
Novice
Sanity check on a macro requirement.
 
Join Date: Aug 2022
Posts: 1
karlkras is on a distinguished road
Question Sanity check on a macro requirement.

I've received a request from my upper management that is wanting the following macro that needs to do the following (it's been a long time since I've worked with vba):

Run a macro that inserts page breaks into a document at every N number of words in the file.
For example, given a word count boundary of 1000 words, starting at the beginning of the file, enumerate through and at every word boundary insert a page break.

I don't see any built in "goto word position" in Word so I'm guessing simply recording a macro to do this isn't possible.



It sounds doable, but just wanted to get an idea of level of difficulty involved and any hurdles (outside of having to refamiliarize myself with the vba development environment) this would impose.

thanks in advanced for any help on this.
Reply With Quote
  #2  
Old 08-17-2022, 09:16 PM
Guessed's Avatar
Guessed Guessed is offline Sanity check on a macro requirement. Windows 10 Sanity check on a macro requirement. 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

Easy to achieve if you are just going every x words. A bit more complex if you want to find x words then adjust forward or back to a paragraph mark.
Code:
Sub Macro1()
  Dim x As Long, lStep As Long
  lStep = 50  'how many words before a page break
  If ActiveDocument.Words.Count > lStep Then
    For x = lStep To ActiveDocument.Words.Count Step lStep
      ActiveDocument.Range.Words(x).InsertAfter Chr(12)
    Next x
  End If
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #3  
Old 08-18-2022, 06:20 AM
macropod's Avatar
macropod macropod is offline Sanity check on a macro requirement. Windows 10 Sanity check on a macro requirement. Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Quote:
Originally Posted by Guessed View Post
Easy to achieve if you are just going every x words. A bit more complex if you want to find x words then adjust forward or back to a paragraph mark.
And rather more complex if you have tables, fields (e.g. tables of contents, cross-references, hyperlinks), content controls, etc. in the document...

Note: Word's idea of a 'word' has nothing to do with grammar.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Have a very specific requirement ggoffice000 Excel Programming 2 02-03-2017 03:47 PM
Sanity check on a macro requirement. Sanity check Ulodesk Word Tables 2 11-01-2016 05:57 AM
Spell check macro within macro button field doesn't work in one document samuelle Word VBA 0 07-20-2016 02:27 AM
Sanity check on a macro requirement. Check Box Macro Johnny thunder Word VBA 12 04-07-2011 04:47 PM
automatic requirement numbering with change detection stijnos Word 0 05-13-2009 12:10 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:20 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