Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / April 2007

Tip: Looking for answers? Try searching our database.

increment year by 1

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jacquie juniorette - 21 Apr 2007 06:16 GMT
I'm creating a master report template and want most (but not all) years in
report to increment by 1.
Tony Jollans - 21 Apr 2007 07:56 GMT
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?

Signature

Enjoy,

Tony Jollans
Microsoft Word MVP

> I'm creating a master report template and want most (but not all) years in
> report to increment by 1.
Jacquie juniorette - 22 Apr 2007 01:22 GMT
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.

> You're going to have to give some more information before anybody can help
> ....
[quoted text clipped - 7 lines]
> > I'm creating a master report template and want most (but not all) years in
> > report to increment by 1.
Tony Jollans - 22 Apr 2007 11:35 GMT
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

Signature

Enjoy,

Tony Jollans
Microsoft Word MVP

> Tony, thanks for the speedy reply.  Sorry for being so thin on details,
> but I
[quoted text clipped - 37 lines]
>> > in
>> > report to increment by 1.
Jacquie juniorette - 22 Apr 2007 14:24 GMT
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.

> If I read you right, all the decisions are manual ones - someone (you) must
> decide what to update and when.
[quoted text clipped - 85 lines]
> >> > in
> >> > report to increment by 1.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.