Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-05-2018, 05:09 PM
Olopocram Olopocram is offline Looking for a macro to increase a number by 1 in a Word document Windows 7 32bit Looking for a macro to increase a number by 1 in a Word document Office 2010 32bit
Novice
Looking for a macro to increase a number by 1 in a Word document
 
Join Date: Mar 2018
Posts: 4
Olopocram is on a distinguished road
Default Looking for a macro to increase a number by 1 in a Word document

Hello,

I have a Word document that other users can access and change (on the same computer). At the top of that document is a line that says "Version # XXX".



What I would like is to be able to run a macro that would increase XXX by 1 and save the document.

Is that possible? How?

Thanks for any reply,
Olopocram

(I run Word 2010)
Reply With Quote
  #2  
Old 03-05-2018, 07:03 PM
macropod's Avatar
macropod macropod is offline Looking for a macro to increase a number by 1 in a Word document Windows 7 64bit Looking for a macro to increase a number by 1 in a Word document Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
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

It's not apparent from your post why a macro would be needed; users could simply overtype the number or, if appears multiple times, use Find/Replace to update it.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 03-05-2018, 08:58 PM
Olopocram Olopocram is offline Looking for a macro to increase a number by 1 in a Word document Windows 7 32bit Looking for a macro to increase a number by 1 in a Word document Office 2010 32bit
Novice
Looking for a macro to increase a number by 1 in a Word document
 
Join Date: Mar 2018
Posts: 4
Olopocram is on a distinguished road
Default

The idea of a macro is to save the hassle of going through the Find/Replace procedure...
Reply With Quote
  #4  
Old 03-05-2018, 09:05 PM
macropod's Avatar
macropod macropod is offline Looking for a macro to increase a number by 1 in a Word document Windows 7 64bit Looking for a macro to increase a number by 1 in a Word document Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
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

A macro that requires one to input the old & new values won't be any faster than pressing Ctrl-H and inputting them directly into the Find/Replace dialogue.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 03-05-2018, 11:27 PM
gmayor's Avatar
gmayor gmayor 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 2016
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

You may find - http://www.gmayor.com/automatic_numbering_documents.htm
and/or
http://www.gmayor.com/SaveVersionsAdd-in.htm
useful. The first linked item stores the number in the template so all users would need access to the same template if they were to share the numbering system.
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #6  
Old 03-06-2018, 06:26 PM
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: 260
eduzs is on a distinguished road
Default

(please delete this reply, code not suitable for the given question)
Reply With Quote
  #7  
Old 03-06-2018, 06:29 PM
macropod's Avatar
macropod macropod is offline Looking for a macro to increase a number by 1 in a Word document Windows 7 64bit Looking for a macro to increase a number by 1 in a Word document Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
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 eduzs View Post
Try this ...
It is supposed to increment the numbering each time the document changes and click Save.
And what happens if the user opens to document to make some edits, but doesn't want to change the numbering?
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #8  
Old 03-06-2018, 06:34 PM
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: 260
eduzs is on a distinguished road
Default

The code will not actually work if there is a document change without change the version number.
Thanks
Reply With Quote
  #9  
Old 03-06-2018, 06:38 PM
macropod's Avatar
macropod macropod is offline Looking for a macro to increase a number by 1 in a Word document Windows 7 64bit Looking for a macro to increase a number by 1 in a Word document Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
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

Your code also won't work unless a Document Variable named 'VNUM' has been created - for which you'd need additional code.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #10  
Old 03-06-2018, 06:42 PM
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: 260
eduzs is on a distinguished road
Default

Yes, it's required to insert once the variable and set it's initial value.
Thanks
Reply With Quote
  #11  
Old 03-07-2018, 01:44 AM
Olopocram Olopocram is offline Looking for a macro to increase a number by 1 in a Word document Windows 7 32bit Looking for a macro to increase a number by 1 in a Word document Office 2010 32bit
Novice
Looking for a macro to increase a number by 1 in a Word document
 
Join Date: Mar 2018
Posts: 4
Olopocram is on a distinguished road
Default

Hello again,

I'm afraid I might not have been very clear.

The idea is this (assuming the macro shortcut is Ctrl+M):

– someone opens doc just to read => Ctrl+W to close (no incrementation)

– someone opens doc and makes a change => Ctrl+M to increment and close

– same person reopens doc to make a slight change => Ctrl+W to close (no incrementation)


The way I see it – but I am not a specialist (this is why I post here) – the version number would be stored in some kind of field within the doc that the macro would only have to read and add 1 to before closing the doc. Thus no user imput needed.

Question is : is it at all possible ?

Thanks to all
Reply With Quote
  #12  
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: 260
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.

Last edited by eduzs; 03-07-2018 at 05:06 AM.
Reply With Quote
  #13  
Old 03-07-2018, 04:39 AM
macropod's Avatar
macropod macropod is offline Looking for a macro to increase a number by 1 in a Word document Windows 7 64bit Looking for a macro to increase a number by 1 in a Word document Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
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 eduzs View Post
(please delete this reply, code not suitable for the given question)
eduzs: Kindly stop deleting your posts after they've been responded to; the practice (which you've employed on a number of occasions now) makes it impossible for anyone else to understand the discussion that has taken place.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #14  
Old 03-07-2018, 05:06 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: 260
eduzs is on a distinguished road
Default

Ok, thanks! I think that this second code is more suitable.
Reply With Quote
  #15  
Old 03-07-2018, 07:18 AM
Olopocram Olopocram is offline Looking for a macro to increase a number by 1 in a Word document Windows 7 32bit Looking for a macro to increase a number by 1 in a Word document Office 2010 32bit
Novice
Looking for a macro to increase a number by 1 in a Word document
 
Join Date: Mar 2018
Posts: 4
Olopocram is on a distinguished road
Default

Works like a breeze! Thanks eduzs and Paul.
Reply With Quote
Reply

Tags
macro, word 10

Thread Tools
Display Modes


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 02:57 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