Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
how do I do this??
Problem Decription:
I have a word 2003 doc that is hundreds of pages long. It is a manual for a program that my company runs every couple of years. The program is a structured 12 month program where the participant has to follow a monthly plan. See below: Month 1 monthly plan, worksheets, readings, exercices, etc. Month 2 monthly plan, worksheets, readings, exercices, etc. .. .. .. Month 12 monthly plan, worksheets, readings, exercices, etc. The program never starts the same month every time is offered. So for example, this year month 1 is August, month 2 is Sept, etc. The person in charge of the program always misses a month here and there when she updates which causes confusion to the participants. I would like to write a macro, where all I would have to do would be to plug in the start month and have it update every instance of the month (staggered by the right amount) throughtout the document. Is that possible?? |
#2
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
how do I do this??
Marf,
I believe that I've seen your message before a few days ago. I too was curious as to how this should be accomplished, and so I tried to watch for answers to your question. Oddly, I was never able to find you message again, until now. The following macro should work. It searches for any text with "Month" followed by a space and a number between 1 and 12. It then substitutes names of the month. It does it in reverse order so that it won't find "Month 11" or "Month 12" when it is looking for "Month 1". ' ' SubstituteMonths searches a document and substitutes "Month 1" with the name ' of the current month; substitutes "Month 2" with the name of the following ' month, etc. ' Sub SubstituteMonths() Dim i As Integer Dim iMonth As Integer For i = 12 To 1 Step -1 iMonth = (Month(Now) - 1) + i If iMonth 12 Then iMonth = iMonth - 12 Selection.HomeKey wdStory, wdMove With Selection.Find .ClearFormatting .Replacement.ClearFormatting .Text = "Month " & i .Replacement.Text = MonthName(iMonth) .Execute Replace:=wdReplaceAll End With Next i End Sub Steven Craig Miller "marf" wrote: Problem Decription: I have a word 2003 doc that is hundreds of pages long. It is a manual for a program that my company runs every couple of years. The program is a structured 12 month program where the participant has to follow a monthly plan. See below: Month 1 monthly plan, worksheets, readings, exercices, etc. Month 2 monthly plan, worksheets, readings, exercices, etc. . . . Month 12 monthly plan, worksheets, readings, exercices, etc. The program never starts the same month every time is offered. So for example, this year month 1 is August, month 2 is Sept, etc. The person in charge of the program always misses a month here and there when she updates which causes confusion to the participants. I would like to write a macro, where all I would have to do would be to plug in the start month and have it update every instance of the month (staggered by the right amount) throughtout the document. Is that possible?? |
#3
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
how do I do this??
marf wrote:
Problem Decription: I have a word 2003 doc that is hundreds of pages long. It is a manual for a program that my company runs every couple of years. The program is a structured 12 month program where the participant has to follow a monthly plan. See below: Month 1 monthly plan, worksheets, readings, exercices, etc. Month 2 monthly plan, worksheets, readings, exercices, etc. . . . Month 12 monthly plan, worksheets, readings, exercices, etc. The program never starts the same month every time is offered. So for example, this year month 1 is August, month 2 is Sept, etc. The person in charge of the program always misses a month here and there when she updates which causes confusion to the participants. I would like to write a macro, where all I would have to do would be to plug in the start month and have it update every instance of the month (staggered by the right amount) throughtout the document. Is that possible?? I hope I understand what you want -- to replace "Month 1" with, say, "June" and then "Month 2" with "July" and so on until "Month 12" is replaced with "May"? Starting with different months in different documents? It's a bit complicated, but this should work. Save the base document as a template and store this macro in it (see http://www.gmayor.com/installing_macro.htm if needed), then make a toolbar button to run the macro. Sub SetMonths() Dim monthList As Variant Dim searchRg As Range Dim strStartMonth As String Dim numStartMonth As Integer Dim docMonth As Integer ' the number in 'Month N' in doc Dim replaceMonth As Integer ' the index of the corresponding ' month name in monthList Dim searchString As String Dim prompt As String monthList = Array("January", "February", "March", _ "April", "May", "June", _ "July", "August", "September", _ "October", "November", "December") prompt = "Enter start month as number " & _ "(1 to 12):" ' ask user what month to start with Do strStartMonth = InputBox(prompt) If Len(strStartMonth) = 0 Then Exit Sub If (Val(strStartMonth) 0) And (Val(strStartMonth) 13) Then numStartMonth = Val(strStartMonth) End If Loop Until numStartMonth 0 ' if we get here, we have a valid month number to start with For docMonth = 12 To 1 Step -1 ' work backward so 'Month 1' doesn't match 'Month 10' etc. ' Figure out the month name to put in this slot. ' The monthList array is zero-based (Jan is 0, Feb is 1...) ' and the last month in the replacements should be the one ' before the startMonth. Thus, subtract 2 from numStartMonth, ' add the current docMonth, and get the result Mod 12: replaceMonth = (numStartMonth - 2 + docMonth) Mod 12 Set searchRg = ActiveDocument.Content With searchRg.Find .Text = "Month " & CStr(docMonth) .Replacement.Text = monthList(replaceMonth) .Forward = True .Wrap = wdFindStop .Format = False .Execute Replace:=wdReplaceOne End With Next End Sub -- Regards, Jay Freedman Microsoft Word MVP FAQ: http://word.mvps.org Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit. |
#4
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
how do I do this??
Thanks Steven and Jay...
I like both ideas, however Steven seems to work better for what I want to do... The only thing I would like to do would be to enter the value of Month 1 rather than it being the current month... How can I do that Steven?? Thanks, Maurice "Jay Freedman" wrote: marf wrote: Problem Decription: I have a word 2003 doc that is hundreds of pages long. It is a manual for a program that my company runs every couple of years. The program is a structured 12 month program where the participant has to follow a monthly plan. See below: Month 1 monthly plan, worksheets, readings, exercices, etc. Month 2 monthly plan, worksheets, readings, exercices, etc. . . . Month 12 monthly plan, worksheets, readings, exercices, etc. The program never starts the same month every time is offered. So for example, this year month 1 is August, month 2 is Sept, etc. The person in charge of the program always misses a month here and there when she updates which causes confusion to the participants. I would like to write a macro, where all I would have to do would be to plug in the start month and have it update every instance of the month (staggered by the right amount) throughtout the document. Is that possible?? I hope I understand what you want -- to replace "Month 1" with, say, "June" and then "Month 2" with "July" and so on until "Month 12" is replaced with "May"? Starting with different months in different documents? It's a bit complicated, but this should work. Save the base document as a template and store this macro in it (see http://www.gmayor.com/installing_macro.htm if needed), then make a toolbar button to run the macro. Sub SetMonths() Dim monthList As Variant Dim searchRg As Range Dim strStartMonth As String Dim numStartMonth As Integer Dim docMonth As Integer ' the number in 'Month N' in doc Dim replaceMonth As Integer ' the index of the corresponding ' month name in monthList Dim searchString As String Dim prompt As String monthList = Array("January", "February", "March", _ "April", "May", "June", _ "July", "August", "September", _ "October", "November", "December") prompt = "Enter start month as number " & _ "(1 to 12):" ' ask user what month to start with Do strStartMonth = InputBox(prompt) If Len(strStartMonth) = 0 Then Exit Sub If (Val(strStartMonth) 0) And (Val(strStartMonth) 13) Then numStartMonth = Val(strStartMonth) End If Loop Until numStartMonth 0 ' if we get here, we have a valid month number to start with For docMonth = 12 To 1 Step -1 ' work backward so 'Month 1' doesn't match 'Month 10' etc. ' Figure out the month name to put in this slot. ' The monthList array is zero-based (Jan is 0, Feb is 1...) ' and the last month in the replacements should be the one ' before the startMonth. Thus, subtract 2 from numStartMonth, ' add the current docMonth, and get the result Mod 12: replaceMonth = (numStartMonth - 2 + docMonth) Mod 12 Set searchRg = ActiveDocument.Content With searchRg.Find .Text = "Month " & CStr(docMonth) .Replacement.Text = monthList(replaceMonth) .Forward = True .Wrap = wdFindStop .Format = False .Execute Replace:=wdReplaceOne End With Next End Sub -- Regards, Jay Freedman Microsoft Word MVP FAQ: http://word.mvps.org Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit. |