Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #13  
Old 03-07-2018, 02:55 AM
eduzs eduzs is offline Looking for a macro to increase a number by 1 in a Word document Windows 10 Looking for a macro to increase a number by 1 in a Word document Office 2010 32bit
Expert
 
Join Date: May 2017
Posts: 266
eduzs is on a distinguished road
Default

Try this:

1st Type this in the document:

"Version #", CTRL+F9 (to insert a field), "{ DOCVARIABLE VNUM }"

Put his code in a module:

Code:
Sub Increment()

On Error Resume Next
With ActiveDocument
    .Variables.Add ("VNUM")
    On Error GoTo 0
    If IsNumeric(.Variables("VNUM")) = False Then
        .Variables("VNUM") = 1
    Else
        If .Saved = False Then
            .Variables("VNUM") = .Variables("VNUM") + 1
        Else
            MsgBox "No changes!"
        End If
    End If
    .Fields.Update
    .Save
    .Close
End With

End Sub
Assign this macro to CTRL+M keyboard shortcut.

The Ctrl+W is really necessary? Why not just save and close the document ?

Test before use, backup your files before, use at your own.
__________________
Backup your original file before doing any modification.

Last edited by eduzs; 03-07-2018 at 05:06 AM.
Reply With Quote
 

Tags
macro, word 10



Similar Threads
Thread Thread Starter Forum Replies Last Post
Increase number in cell, based on value in adjacent cell scottyb Excel 3 02-02-2017 03:51 AM
How to find number of coma and then add that number of rows in word using macro? PRA007 Word VBA 7 05-27-2015 10:45 PM
Looking for a macro to increase a number by 1 in a Word document Global macro across a number of different word files daffy Word VBA 6 07-08-2014 05:42 PM
Createing Macro to Increase Margin by 1pt thundercats9595 Word VBA 2 01-29-2014 12:36 PM
Looking for a macro to increase a number by 1 in a Word document Increase serial number for every print atomtm Word 1 06-15-2012 05:39 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 09:08 PM.


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