increment year by 1

J

Jacquie juniorette

I'm creating a master report template and want most (but not all) years in
report to increment by 1.
 
T

Tony Jollans

You're going to have to give some more information before anybody can help
....

How often and/or under what circumstances do you want the years to
increment?

How can the years (both those you want incremented and those you don't) be
identifed in the template and/or documents based on it?
 
J

Jacquie juniorette

Tony, thanks for the speedy reply. Sorry for being so thin on details, but I
hate to punish innocent bystanders by talking about my job. Where I work, we
have approx. 30 20-25 pg. valuation reports in Word 2003, updated annually,
that I’m working on getting into one template. Each report contains 10-15
different years, formatted as January 1, 2007, 1/1/2007, 1/1/00 or 1-1-00
(the month can vary). I’ve been using Edit/Replace which is the suckiest way
on Earth to do it.

The circumstance that decides if the year should change is whether the info
for a year is being updated (which means it should increment) or whether it’s
historical (year stays the same). There’s no one indicator I can pinpoint
immediately before or after to mark the year as one that should change. My
idea (but you may have a far better one) is to bookmark each year in the
template that needs to change, and then have a macro that will increment the
bookmarked years by 1. There are about 100 yearly reports that wouldn’t fit
into this template so my idea is quite far from a perfect solution, but I
figured I could at least get the reports that are similar into 1 template.
 
T

Tony Jollans

If I read you right, all the decisions are manual ones - someone (you) must
decide what to update and when.

If the dates simply appear as text in (as far as any automated process is
concerned) random positions then, essentially, whatever you do is just a
glorified Find and Replace operation and, without more knowledge of your
reports, bookmarks are as good as any other method for identifying them.

As for templates, they serve many purposes. When new documents are created
from them, they serve, loosely, as bolierplate text - that may be useful to
you but is not relevant to the incrementing issue. Templates also serve as
containers for macros and it is this function of them that is currently of
interest. To use a macro in a template it is necessary only for the template
to be loaded, not for it to be attached to the document; whether or not a
document 'fits' a template is not relevant in this context. Reading between
the lines you are doing this yourself so if you have an appropriate template
available to you (in your StartUp folder perhaps) it should be sufficient -
and also prevent other people accidentally running your macro(s) when they
shouldn't.

If each of your years (just the years) for incrementing is bookmarked with a
name beginning "IncrementYear" then this rough'n'ready macro should
increment them for you ...

Sub Increment()
Const Ident = "IncrementYear"
Dim x As Long
Dim B As Word.Bookmark
Dim R As Word.Range
Dim BName As String
Dim YText As String
For x = ActiveDocument.Bookmarks.Count To 1 Step -1
Set B = ActiveDocument.Bookmarks(x)
If Left(B.Name, Len(Ident)) = Ident Then
If IsNumeric(B.Range) Then
Set R = B.Range.Duplicate
BName = B.Name
YText = Val(R.Text) + 1
If Len(YText) < Len(R.Text) Then
YText = Right(String(Len(R.Text), "0") & YText, Len(R.Text))
End If
R.Text = YText
ActiveDocument.Bookmarks.Add BName, R
End If
End If
Next
End Sub
 
J

Jacquie juniorette

Tony, I’m pretty new at using macros, so I’m going to try this out when I get
to work Monday (if they leave me in peace for 2 minutes) and let you know how
it goes. Thanks for yet another speedy reply. I posted this question well
before the template was done thinking I might have to wait a week or two for
a reply. I look forward to the time when I'll be able to hand out macro
advice.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top