Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-30-2020, 07:23 AM
Fred Doolie Fred Doolie is offline Auto-incrementing variable needed for macro - to automatically increment chapter numbering & headers Windows 10 Auto-incrementing variable needed for macro - to automatically increment chapter numbering & headers Office 2010
Novice
Auto-incrementing variable needed for macro - to automatically increment chapter numbering & headers
 
Join Date: Jan 2019
Posts: 3
Fred Doolie is on a distinguished road
Default Auto-incrementing variable needed for macro - to automatically increment chapter numbering & headers

How do I put an automatically incrementing value into a macro? I'm writing a book and have created a macro to start a chapter. It does a page break, goes into header 1 mode, enters "Chapter XXX", goes into chaper title mode and enters "CHAPTER TITLE", then drops down a line and enters normal mode.
I'd like to replace that "XXX" with something that would increment every time I used the macro. That way I don't have to keep scrolling back to see what the current chapter should be.

Last edited by Charles Kenyon; 06-30-2020 at 08:05 AM. Reason: Change title to give better info about question
Reply With Quote
  #2  
Old 06-30-2020, 08:02 AM
Charles Kenyon Charles Kenyon is offline Auto-incrementing variable needed for macro - to automatically increment chapter numbering & headers Windows 10 Auto-incrementing variable needed for macro - to automatically increment chapter numbering & headers Office 2019
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,081
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

First, stop messing with the header. Use the StyleRef Field instead. That is what it is designed to do.

Second, consider using AutoMatic Numbering tied to your Heading 1 or another style.
How to create numbered headings or outline numbering in Ribbon Versions of Word by Shauna Kelly
If you want to add a chapter heading, apply the style. If you add in the middle, it automatically updates everything after.

This also gives you a good start on your Table of Contents.
Generating a Table of Contents
Why use Microsoft Word’s built-in heading styles? by Shauna Kelly

If you really, really, want to do this the hard way, you could save your number as a custom document property.
How to use a single VBA procedure to read or write both custom and
built-in Document Properties


To me, is seems like you are trying to re-invent the wheel. This stuff is built into Word.
Reply With Quote
  #3  
Old 06-30-2020, 03:13 PM
Fred Doolie Fred Doolie is offline Auto-incrementing variable needed for macro - to automatically increment chapter numbering & headers Windows 10 Auto-incrementing variable needed for macro - to automatically increment chapter numbering & headers Office 2010
Novice
Auto-incrementing variable needed for macro - to automatically increment chapter numbering & headers
 
Join Date: Jan 2019
Posts: 3
Fred Doolie is on a distinguished road
Default

After hours of searching the net I found the answer and it's simple as anything.
Ues header 1 for the chapters and set it like this picture:



Screenshot by Lightshot


Problem solved.
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Custom auto incrementing integer prefixes on headers ritmo2k Word 2 03-09-2018 06:39 AM
Macro needed for time calculation and auto insert ballst Excel Programming 8 05-21-2015 03:54 PM
Auto Incrementing source for data validation OfficeTemp99 Excel 1 05-13-2015 06:36 AM
Auto-incrementing variable needed for macro - to automatically increment chapter numbering & headers Preventing Auto Metadata - Help Needed! samcmakin Word 1 04-09-2015 11:48 PM
Auto-incrementing variable needed for macro - to automatically increment chapter numbering & headers Outlook 2007 Auto-Reply: Help needed gpang788 Outlook 5 11-09-2010 04:12 PM

Other Forums: Access Forums

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