Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.word.newusers
|
|||
|
|||
Macro Help Needed
Can someone help me create a macro for Word 2007/2010 that will scan a document and place any text between quotation marks in italics. I routinely quote sources and scripture passages in my work as a pastor and have been doing this mannually and would like to automate this process. Thanks, Michael |
#2
Posted to microsoft.public.word.newusers
|
|||
|
|||
Macro Help Needed
Rev. Burns:
Sub WordsInQuotes() Dim myRange As Range Dim myString As String Set myRange = ActiveDocument.Range With myRange Do While ..Find.Execute(FindText:="[^0147^01486^34][A-Za-z]{1,}[^0147^01486^34]", _ MatchWildcards:=True, Wrap:=wdFindStop, Forward:=True) = True '.MoveStart Unit:=wdCharacter, Count:=1 '.MoveEnd Unit:=wdCharacter, Count:=-1 .Font.Italic = True .Collapse Direction:=wdCollapseEnd Loop End With Set myRange = Nothing End Sub The code includes the quotation marks making them italic as well. I you just want the text (i.e., leave the marks themselves alone) then remove the stet marks ' from the the two Move lines. -- Greg Maxey - Word MVP My web site http://gregmaxey.mvps.org Word MVP web site http://word.mvps.org "Rev. Michael L. Burns" wrote in message . com... Can someone help me create a macro for Word 2007/2010 that will scan a document and place any text between quotation marks in italics. I routinely quote sources and scripture passages in my work as a pastor and have been doing this mannually and would like to automate this process. Thanks, Michael |
#3
Posted to microsoft.public.word.newusers
|
|||
|
|||
Macro Help Needed
Hello Greg,
Thanks for the macro Help. I'll give it a try when I get back ri rhe office on Tuesday. Could I impose on you again for help with two more macros that would make my work simpler? First, because of failing eyesite I have set my default font and font size on all documents to Times Romans, 16pt which makes my notes very readable. However, I routinely go through my completed documents and change the font size between paragraphs to 6pt. Can a macro be made to do this automaticully? Second, when teaching a class or preaching, I have for years picked a key word from my notes and encouraged the children (although I have found the adults get involved as well) to count how often I use the word in my message or lesson. I then give the child who comes the closest to the key word count in my manuscript a prize, usually a candy bar or the likes. This had greatly incread how much the children, and even the adults, pay attention. Prior to upgrading from Word 2000 to Word 2007 I used a macro that someone, I've forgotten who, made for me that would open a dialog box that would ask for the key word and then scan the document and give me a total of how many times that word was used in the notes. However, I no longer have the macro (forgot to save the code) when I did a clean install on my system at the same time I updated to Office 2007. Could you help in this macro as well with one change if it possible? After entering the key word in the dialog box and having the macro scan my document for the times the key word is used, instead of displaying the total count in a message box like the old macro used to, if possible I'd like to have the macro incert a line in my document that would say something like "Key Word for Today, XXX, is Used YYY Times" where XXX is the Key Word and YYY is the number of times it is used. I always start my notes with three lines, centered in bold print, which are the sermon or lesson title, the text under study, and the date. I'd like the line inserted in bold print and centered after the date which would mean at the fourth line. If this could be done, I'd really appreaciate it. If not I could live with the way the old macro worked. I know this is a lot to ask but I'm dumber than an oyster win it comes to coding macros. Any help would be greatly appreciated and thanks again for the italicised quote macro. Pastor Burns Rev. Burns: Sub WordsInQuotes() Dim myRange As Range Dim myString As String Set myRange = ActiveDocument.Range With myRange Do While .Find.Execute(FindText:="[^0147^01486^34][A-Za-z]{1,}[^0147^01486^34]" , _ MatchWildcards:=True, Wrap:=wdFindStop, Forward:=True) = True '.MoveStart Unit:=wdCharacter, Count:=1 '.MoveEnd Unit:=wdCharacter, Count:=-1 .Font.Italic = True .Collapse Direction:=wdCollapseEnd Loop End With Set myRange = Nothing End Sub The code includes the quotation marks making them italic as well. I you just want the text (i.e., leave the marks themselves alone) then remove the stet marks ' from the the two Move lines. |
#4
Posted to microsoft.public.word.newusers
|
|||
|
|||
Macro Help Needed
Reverend Burns,
You are welcome. The solution you seek for your first question doesn't really not require a macro. If I understand you correctly, you have the habit of pressing enter twice to place a blank paragraph between your current text paragraph and a new text paragraph and then you want to format that empty paragraph with font size 6. A better approach would be to create a paragraph style for your sermon notes that uses Times New Roman 16 pt and 6 points of space after the paragraph. Hit the enter key once to start a new paragraph. However, if you really want to stick with your current method you could use: Sub ScratchMacro() Dim oPar As Paragraph For Each oPar In ActiveDocument.Range.Paragraphs If Len(oPar.Range.Text) = 1 Then oPar.Range.Font.Size = 8 End If Next oPar End Sub For the second request you could use something like this: Sub ScratchKeyWordMacro() Dim oRNg As Word.Range Dim i As Long Dim pWord As String Set oRNg = ActiveDocument.Range pWord = InputBox("Enter the keyword:", "Key Word") With oRNg.Find .Text = pWord .MatchCase = False .MatchWholeWord = True While .Execute i = i + 1 oRNg.Collapse wdCollapseEnd Wend End With Set oRNg = ActiveDocument.Bookmarks("Keyword").Range oRNg.Text = "Keyword for today, " & pWord & ", is Used " & i & " Times" ActiveDocument.Bookmarks.Add "Keyword", oRNg End Sub Use the Ribbon Insert Tab, Links Group, Bookmarks control to insert a bookmark exactly where you want the results to appear. Name the bookmark "Keyword" Good luck. Greg Maxey - Word MVP My web site http://gregmaxey.mvps.org Word MVP web site http://word.mvps.org "Rev. Michael L. Burns" wrote in message . com... Hello Greg, Thanks for the macro Help. I'll give it a try when I get back ri rhe office on Tuesday. Could I impose on you again for help with two more macros that would make my work simpler? First, because of failing eyesite I have set my default font and font size on all documents to Times Romans, 16pt which makes my notes very readable. However, I routinely go through my completed documents and change the font size between paragraphs to 6pt. Can a macro be made to do this automaticully? Second, when teaching a class or preaching, I have for years picked a key word from my notes and encouraged the children (although I have found the adults get involved as well) to count how often I use the word in my message or lesson. I then give the child who comes the closest to the key word count in my manuscript a prize, usually a candy bar or the likes. This had greatly incread how much the children, and even the adults, pay attention. Prior to upgrading from Word 2000 to Word 2007 I used a macro that someone, I've forgotten who, made for me that would open a dialog box that would ask for the key word and then scan the document and give me a total of how many times that word was used in the notes. However, I no longer have the macro (forgot to save the code) when I did a clean install on my system at the same time I updated to Office 2007. Could you help in this macro as well with one change if it possible? After entering the key word in the dialog box and having the macro scan my document for the times the key word is used, instead of displaying the total count in a message box like the old macro used to, if possible I'd like to have the macro incert a line in my document that would say something like "Key Word for Today, XXX, is Used YYY Times" where XXX is the Key Word and YYY is the number of times it is used. I always start my notes with three lines, centered in bold print, which are the sermon or lesson title, the text under study, and the date. I'd like the line inserted in bold print and centered after the date which would mean at the fourth line. If this could be done, I'd really appreaciate it. If not I could live with the way the old macro worked. I know this is a lot to ask but I'm dumber than an oyster win it comes to coding macros. Any help would be greatly appreciated and thanks again for the italicised quote macro. Pastor Burns Rev. Burns: Sub WordsInQuotes() Dim myRange As Range Dim myString As String Set myRange = ActiveDocument.Range With myRange Do While .Find.Execute(FindText:="[^0147^01486^34][A-Za-z]{1,}[^0147^01486^34]" , _ MatchWildcards:=True, Wrap:=wdFindStop, Forward:=True) = True '.MoveStart Unit:=wdCharacter, Count:=1 '.MoveEnd Unit:=wdCharacter, Count:=-1 .Font.Italic = True .Collapse Direction:=wdCollapseEnd Loop End With Set myRange = Nothing End Sub The code includes the quotation marks making them italic as well. I you just want the text (i.e., leave the marks themselves alone) then remove the stet marks ' from the the two Move lines. |
#5
Posted to microsoft.public.word.newusers
|
|||
|
|||
Macro Help Needed
Hello Again Greg,
I had to run ro rhe office to fetch some papers. I tried the WordsInQuotes macro while I was there and it shows a compile error in the DoWhile routinr.. There did appear to be a missing contenuation mark ( _) afer Wrap:=wdFindStop, but I still get an error. Michael Rev. Burns: Sub WordsInQuotes() Dim myRange As Range Dim myString As String Set myRange = ActiveDocument.Range With myRange Do While .Find.Execute(FindText:="[^0147^01486^34][A-Za-z]{1,}[^0147^01486^34]" , _ MatchWildcards:=True, Wrap:=wdFindStop, Forward:=True) = True '.MoveStart Unit:=wdCharacter, Count:=1 '.MoveEnd Unit:=wdCharacter, Count:=-1 .Font.Italic = True .Collapse Direction:=wdCollapseEnd Loop End With Set myRange = Nothing End Sub The code includes the quotation marks making them italic as well. I you just want the text (i.e., leave the marks themselves alone) then remove the stet marks ' from the the two Move lines. My web site http://gregmaxey.mvps.org Word MVP web site http://word.mvps.org "Rev. Michael L. Burns" wrote in message . com... Can someone help me create a macro for Word 2007/2010 that will scan a document and place any text between quotation marks in italics. I routinely quote sources and scripture passages in my work as a pastor and have been doing this mannually and would like to automate this process. Thanks, Michael |
#6
Posted to microsoft.public.word.newusers
|
|||
|
|||
Macro Help Needed
Try this:
Sub WordsInQuotes() Dim myRange As Range Dim myString As String Set myRange = ActiveDocument.Range With myRange.Find .Text = "[^0147^01486^34]*[^0147^01486^34]" .MatchWildcards = True .Wrap = wdFindStop .Forward = True While .Execute With myRange .MoveStart Unit:=wdCharacter, Count:=1 .MoveEnd Unit:=wdCharacter, Count:=-1 .Font.Italic = True .Collapse Direction:=wdCollapseEnd End With Wend End With Set myRange = Nothing End Sub Rev. Michael L. Burns wrote: Hello Again Greg, I had to run ro rhe office to fetch some papers. I tried the WordsInQuotes macro while I was there and it shows a compile error in the DoWhile routinr.. There did appear to be a missing contenuation mark ( _) afer Wrap:=wdFindStop, but I still get an error. Michael Rev. Burns: Sub WordsInQuotes() Dim myRange As Range Dim myString As String Set myRange = ActiveDocument.Range With myRange Do While .Find.Execute(FindText:="[^0147^01486^34][A-Za-z]{1,}[^0147^01486^34]" , _ MatchWildcards:=True, Wrap:=wdFindStop, Forward:=True) = True '.MoveStart Unit:=wdCharacter, Count:=1 '.MoveEnd Unit:=wdCharacter, Count:=-1 .Font.Italic = True .Collapse Direction:=wdCollapseEnd Loop End With Set myRange = Nothing End Sub The code includes the quotation marks making them italic as well. I you just want the text (i.e., leave the marks themselves alone) then remove the stet marks ' from the the two Move lines. My web site http://gregmaxey.mvps.org Word MVP web site http://word.mvps.org "Rev. Michael L. Burns" wrote in message . com... Can someone help me create a macro for Word 2007/2010 that will scan a document and place any text between quotation marks in italics. I routinely quote sources and scripture passages in my work as a pastor and have been doing this mannually and would like to automate this process. Thanks, Michael -- Greg Maxey - Word MVP My web site http://gregmaxey.mvps.org Word MVP web site http://word.mvps.org |
#7
Posted to microsoft.public.word.newusers
|
|||
|
|||
Macro Help Needed
Hello Greg,
That's better but still has a problem. If I type the following: "This is test 1" This is test 2 "This is test 3" It changes eveything to italics. I tried it on a document I was working on and it did the same thing, italisized the whole document. Michael Dim myRange As Range Dim myString As String Set myRange = ActiveDocument.Range With myRange.Find .Text = "[^0147^01486^34]*[^0147^01486^34]" .MatchWildcards = True .Wrap = wdFindStop .Forward = True While .Execute With myRange .MoveStart Unit:=wdCharacter, Count:=1 .MoveEnd Unit:=wdCharacter, Count:=-1 .Font.Italic = True .Collapse Direction:=wdCollapseEnd End With Wend End With Set myRange = Nothing |
#8
Posted to microsoft.public.word.newusers
|
|||
|
|||
Macro Help Needed
Hello Greg,
The WordsInQuotes macro now works great. Thanks. I had to add the stet marks in the Move Statements to comment then out as follows: '.MoveStart Unit:=wdCharacter, Count:=1 '.MoveEnd Unit:=wdCharacter, Count:=-1 Michael Try this: Sub WordsInQuotes() Dim myRange As Range Dim myString As String Set myRange = ActiveDocument.Range With myRange.Find .Text = "[^0147^01486^34]*[^0147^01486^34]" .MatchWildcards = True .Wrap = wdFindStop .Forward = True While .Execute With myRange .MoveStart Unit:=wdCharacter, Count:=1 .MoveEnd Unit:=wdCharacter, Count:=-1 .Font.Italic = True .Collapse Direction:=wdCollapseEnd End With Wend End With Set myRange = Nothing End Sub Rev. Michael L. Burns wrote: Hello Again Greg, I had to run ro rhe office to fetch some papers. I tried the WordsInQuotes macro while I was there and it shows a compile error in the DoWhile routinr.. There did appear to be a missing contenuation mark ( _) afer Wrap:=wdFindStop, but I still get an error. Michael Rev. Burns: Sub WordsInQuotes() Dim myRange As Range Dim myString As String Set myRange = ActiveDocument.Range With myRange Do While .Find.Execute(FindText:="[^0147^01486^34][A-Za-z]{1,}[^0147^01486^34 ]" , _ MatchWildcards:=True, Wrap:=wdFindStop, Forward:=True) = True '.MoveStart Unit:=wdCharacter, Count:=1 '.MoveEnd Unit:=wdCharacter, Count:=-1 .Font.Italic = True .Collapse Direction:=wdCollapseEnd Loop End With Set myRange = Nothing End Sub The code includes the quotation marks making them italic as well. I you just want the text (i.e., leave the marks themselves alone) then remove the stet marks ' from the the two Move lines. My web site http://gregmaxey.mvps.org Word MVP web site http://word.mvps.org "Rev. Michael L. Burns" wrote in message . com... Can someone help me create a macro for Word 2007/2010 that will scan a document and place any text between quotation marks in italics. I routinely quote sources and scripture passages in my work as a pastor and have been doing this mannually and would like to automate this process. Thanks, Michael My web site http://gregmaxey.mvps.org Word MVP web site http://word.mvps.org |
#9
Posted to microsoft.public.word.newusers
|
|||
|
|||
Macro Help Needed
Hello Greg,
The Scratch macro works great but I may eventually creat a style as you suggested as soon as I learn a little more. The Keyword macro works great with one exception. Is there a way to have it add a blank line after the message is inserted at the bookmark? Right now, unless I manually insert two blank lines between the date and the body of the document the tope of the document looks something like this: Check Your Baggage Here Matthew 11:28-30 August 22, 2009 Keyword for today, Baggage, is Used 36 Times Come to Me, all who are weary and heavy-laden, and I will give you rest. Take My yoke upon you, and learn from Me, for I am gentle and humble in heart; and you shall find rest for your souls. For My yoke is easy, and My load is light." (Matthew 11:28-30) I can live with it the way it is but it would be nice to automate the whole process. I reallu appreciate your time and assistance. Michael Reverend Burns, You are welcome. The solution you seek for your first question doesn't really not require a macro. If I understand you correctly, you have the habit of pressing enter twice to place a blank paragraph between your current text paragraph and a new text paragraph and then you want to format that empty paragraph with font size 6. A better approach would be to create a paragraph style for your sermon notes that uses Times New Roman 16 pt and 6 points of space after the paragraph. Hit the enter key once to start a new paragraph. However, if you really want to stick with your current method you could use: Sub ScratchMacro() Dim oPar As Paragraph For Each oPar In ActiveDocument.Range.Paragraphs If Len(oPar.Range.Text) = 1 Then oPar.Range.Font.Size = 8 End If Next oPar End Sub For the second request you could use something like this: Sub ScratchKeyWordMacro() Dim oRNg As Word.Range Dim i As Long Dim pWord As String Set oRNg = ActiveDocument.Range pWord = InputBox("Enter the keyword:", "Key Word") With oRNg.Find .Text = pWord .MatchCase = False .MatchWholeWord = True While .Execute i = i + 1 oRNg.Collapse wdCollapseEnd Wend End With Set oRNg = ActiveDocument.Bookmarks("Keyword").Range oRNg.Text = "Keyword for today, " & pWord & ", is Used " & i & " Times" ActiveDocument.Bookmarks.Add "Keyword", oRNg End Sub Use the Ribbon Insert Tab, Links Group, Bookmarks control to insert a bookmark exactly where you want the results to appear. Name the bookmark "Keyword" Good luck. Greg Maxey - Word MVP My web site http://gregmaxey.mvps.org Word MVP web site http://word.mvps.org "Rev. Michael L. Burns" wrote in message . com... Hello Greg, Thanks for the macro Help. I'll give it a try when I get back ri rhe office on Tuesday. Could I impose on you again for help with two more macros that would make my work simpler? First, because of failing eyesite I have set my default font and font size on all documents to Times Romans, 16pt which makes my notes very readable. However, I routinely go through my completed documents and change the font size between paragraphs to 6pt. Can a macro be made to do this automaticully? Second, when teaching a class or preaching, I have for years picked a key word from my notes and encouraged the children (although I have found the adults get involved as well) to count how often I use the word in my message or lesson. I then give the child who comes the closest to the key word count in my manuscript a prize, usually a candy bar or the likes. This had greatly incread how much the children, and even the adults, pay attention. Prior to upgrading from Word 2000 to Word 2007 I used a macro that someone, I've forgotten who, made for me that would open a dialog box that would ask for the key word and then scan the document and give me a total of how many times that word was used in the notes. However, I no longer have the macro (forgot to save the code) when I did a clean install on my system at the same time I updated to Office 2007. Could you help in this macro as well with one change if it possible? After entering the key word in the dialog box and having the macro scan my document for the times the key word is used, instead of displaying the total count in a message box like the old macro used to, if possible I'd like to have the macro incert a line in my document that would say something like "Key Word for Today, XXX, is Used YYY Times" where XXX is the Key Word and YYY is the number of times it is used. I always start my notes with three lines, centered in bold print, which are the sermon or lesson title, the text under study, and the date. I'd like the line inserted in bold print and centered after the date which would mean at the fourth line. If this could be done, I'd really appreaciate it. If not I could live with the way the old macro worked. I know this is a lot to ask but I'm dumber than an oyster win it comes to coding macros. Any help would be greatly appreciated and thanks again for the italicised quote macro. Pastor Burns Rev. Burns: Sub WordsInQuotes() Dim myRange As Range Dim myString As String Set myRange = ActiveDocument.Range With myRange Do While .Find.Execute(FindText:="[^0147^01486^34][A-Za-z]{1,}[^0147^01486^34 ]" , _ MatchWildcards:=True, Wrap:=wdFindStop, Forward:=True) = True '.MoveStart Unit:=wdCharacter, Count:=1 '.MoveEnd Unit:=wdCharacter, Count:=-1 .Font.Italic = True .Collapse Direction:=wdCollapseEnd Loop End With Set myRange = Nothing End Sub The code includes the quotation marks making them italic as well. I you just want the text (i.e., leave the marks themselves alone) then remove the stet marks ' from the the two Move lines. |
#10
Posted to microsoft.public.word.newusers
|
|||
|
|||
Macro Help Needed
The keyword macro below includes your request for more space. I have taken
the liberty of adding a routine to check for the presence of the bookmark and if it is not in the document it will be created at the cursor. Sub ScratchKeyWordMacro() Dim oRNg As Word.Range Dim i As Long Dim bExists As Boolean Dim vBM As Variant Dim oBMs As Bookmarks Dim pWord As String Dim sNum As String Set oRNg = ActiveDocument.Range Set oBMs = ActiveDocument.Bookmarks For Each vBM In oBMs If vBM.name = "Keyword" Then bExists = True Exit For End If Next vBM If bExists = False Then ActiveDocument.Bookmarks.Add "Keyword", Selection.Range End If pWord = InputBox("Enter the keyword:", "Key Word") With oRNg.Find .Text = pWord .MatchCase = False .MatchWholeWord = True While .Execute i = i + 1 oRNg.Collapse wdCollapseEnd Wend End With pWord = Chr(34) & UCase(pWord) & Chr(34) Select Case i Case Is = 1 sNum = "once" Case Is = 2 sNum = "twice" Case Else sNum = i & " times" End Select Set oRNg = ActiveDocument.Bookmarks("Keyword").Range oRNg.Text = "Keyword for today, " & pWord & ", is used " & sNum & vbCr oRNg.ParagraphFormat.SpaceAfter = 16 ActiveDocument.Bookmarks.Add "Keyword", oRNg End Sub -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org Rev. Michael L. Burns wrote: Hello Greg, The Scratch macro works great but I may eventually creat a style as you suggested as soon as I learn a little more. The Keyword macro works great with one exception. Is there a way to have it add a blank line after the message is inserted at the bookmark? Right now, unless I manually insert two blank lines between the date and the body of the document the tope of the document looks something like this: Check Your Baggage Here Matthew 11:28-30 August 22, 2009 Keyword for today, Baggage, is Used 36 Times Come to Me, all who are weary and heavy-laden, and I will give you rest. Take My yoke upon you, and learn from Me, for I am gentle and humble in heart; and you shall find rest for your souls. For My yoke is easy, and My load is light." (Matthew 11:28-30) I can live with it the way it is but it would be nice to automate the whole process. I reallu appreciate your time and assistance. Michael Reverend Burns, You are welcome. The solution you seek for your first question doesn't really not require a macro. If I understand you correctly, you have the habit of pressing enter twice to place a blank paragraph between your current text paragraph and a new text paragraph and then you want to format that empty paragraph with font size 6. A better approach would be to create a paragraph style for your sermon notes that uses Times New Roman 16 pt and 6 points of space after the paragraph. Hit the enter key once to start a new paragraph. However, if you really want to stick with your current method you could use: Sub ScratchMacro() Dim oPar As Paragraph For Each oPar In ActiveDocument.Range.Paragraphs If Len(oPar.Range.Text) = 1 Then oPar.Range.Font.Size = 8 End If Next oPar End Sub For the second request you could use something like this: Sub ScratchKeyWordMacro() Dim oRNg As Word.Range Dim i As Long Dim pWord As String Set oRNg = ActiveDocument.Range pWord = InputBox("Enter the keyword:", "Key Word") With oRNg.Find .Text = pWord .MatchCase = False .MatchWholeWord = True While .Execute i = i + 1 oRNg.Collapse wdCollapseEnd Wend End With Set oRNg = ActiveDocument.Bookmarks("Keyword").Range oRNg.Text = "Keyword for today, " & pWord & ", is Used " & i & " Times" ActiveDocument.Bookmarks.Add "Keyword", oRNg End Sub Use the Ribbon Insert Tab, Links Group, Bookmarks control to insert a bookmark exactly where you want the results to appear. Name the bookmark "Keyword" Good luck. Greg Maxey - Word MVP My web site http://gregmaxey.mvps.org Word MVP web site http://word.mvps.org "Rev. Michael L. Burns" wrote in message . com... Hello Greg, Thanks for the macro Help. I'll give it a try when I get back ri rhe office on Tuesday. Could I impose on you again for help with two more macros that would make my work simpler? First, because of failing eyesite I have set my default font and font size on all documents to Times Romans, 16pt which makes my notes very readable. However, I routinely go through my completed documents and change the font size between paragraphs to 6pt. Can a macro be made to do this automaticully? Second, when teaching a class or preaching, I have for years picked a key word from my notes and encouraged the children (although I have found the adults get involved as well) to count how often I use the word in my message or lesson. I then give the child who comes the closest to the key word count in my manuscript a prize, usually a candy bar or the likes. This had greatly incread how much the children, and even the adults, pay attention. Prior to upgrading from Word 2000 to Word 2007 I used a macro that someone, I've forgotten who, made for me that would open a dialog box that would ask for the key word and then scan the document and give me a total of how many times that word was used in the notes. However, I no longer have the macro (forgot to save the code) when I did a clean install on my system at the same time I updated to Office 2007. Could you help in this macro as well with one change if it possible? After entering the key word in the dialog box and having the macro scan my document for the times the key word is used, instead of displaying the total count in a message box like the old macro used to, if possible I'd like to have the macro incert a line in my document that would say something like "Key Word for Today, XXX, is Used YYY Times" where XXX is the Key Word and YYY is the number of times it is used. I always start my notes with three lines, centered in bold print, which are the sermon or lesson title, the text under study, and the date. I'd like the line inserted in bold print and centered after the date which would mean at the fourth line. If this could be done, I'd really appreaciate it. If not I could live with the way the old macro worked. I know this is a lot to ask but I'm dumber than an oyster win it comes to coding macros. Any help would be greatly appreciated and thanks again for the italicised quote macro. Pastor Burns Rev. Burns: Sub WordsInQuotes() Dim myRange As Range Dim myString As String Set myRange = ActiveDocument.Range With myRange Do While .Find.Execute(FindText:="[^0147^01486^34][A-Za-z]{1,}[^0147^01486^34 ]" , _ MatchWildcards:=True, Wrap:=wdFindStop, Forward:=True) = True '.MoveStart Unit:=wdCharacter, Count:=1 '.MoveEnd Unit:=wdCharacter, Count:=-1 .Font.Italic = True .Collapse Direction:=wdCollapseEnd Loop End With Set myRange = Nothing End Sub The code includes the quotation marks making them italic as well. I you just want the text (i.e., leave the marks themselves alone) then remove the stet marks ' from the the two Move lines. |
#11
Posted to microsoft.public.word.newusers
|
|||
|
|||
Macro Help Needed
Pastor Burns,
It was a little late last night so I omitted some of the bells and whistles that my friend Graham later added. He and I use a little different style so I would have approached the possibility of the missing bookmark as follows: Sub ScratchKeyWordMacro() Dim oRng As Word.Range Dim i As Long Dim oBMs As Bookmarks Dim pWord As String Dim sNum As String Set oBMs = ActiveDocument.Bookmarks On Error Resume Next Set oRng = oBMs("Keyword").Range If Err.Number = 5941 Then 'Error is produced if BM doesn't exist. Set oRng = Selection.Range oBMs.Add "Keyword", oRng End If On Error GoTo 0 Set oRng = ActiveDocument.Range pWord = InputBox("Enter the keyword:", "Key Word") With oRng.Find .Text = pWord .MatchCase = False .MatchWholeWord = True While .Execute i = i + 1 oRng.Collapse wdCollapseEnd Wend End With pWord = Chr(34) & UCase(pWord) & Chr(34) Select Case i Case Is = 1 sNum = "once" Case Is = 2 sNum = "twice" Case Else sNum = i & " times" End Select Set oRng = ActiveDocument.Bookmarks("Keyword").Range oRng.Text = "Keyword for today, " & pWord & ", is used " & sNum & vbCr oRng.ParagraphFormat.SpaceAfter = 16 ActiveDocument.Bookmarks.Add "Keyword", oRng End Sub With either code, all you have to do is put your cursor where you want the statistic to appear and run the code. While not impossible, it could be a little difficult to place the bookmark for you automatically because of your practice of using empty paragraphs. I think a reasonable approach would be for you to create a template for your notes that already contains the bookmark at the proper location whenever you start a new document based on the template. Again it was late when I made the modification to the quote macro. It is supposed to work (and now does) regardless if yo want the qoute marks themselves included in the italic format or left as is. Unsetting the three lines belong excludes the marks. Leaving them to run includes the marks. Sub WordsInQuotes() Dim myRange As Range Dim myString As String Set myRange = ActiveDocument.Range With myRange.Find .Text = "[^0147^01486^34]*[^0147^01486^34]" .MatchWildcards = True .Wrap = wdFindStop .Forward = True While .Execute With myRange '.MoveStart Unit:=wdCharacter, Count:=1 '.MoveEnd Unit:=wdCharacter, Count:=-1 .Font.Italic = True .Collapse Direction:=wdCollapseEnd '.MoveStart Unit:=wdCharacter, Count:=1 End With Wend End With Set myRange = Nothing End Sub -- Greg Maxey - Word MVP My web site http://gregmaxey.mvps.org Word MVP web site http://word.mvps.org "Rev. Michael L. Burns" wrote in message . com... Hello Greg, The Scratch macro works great but I may eventually creat a style as you suggested as soon as I learn a little more. The Keyword macro works great with one exception. Is there a way to have it add a blank line after the message is inserted at the bookmark? Right now, unless I manually insert two blank lines between the date and the body of the document the tope of the document looks something like this: Check Your Baggage Here Matthew 11:28-30 August 22, 2009 Keyword for today, Baggage, is Used 36 Times Come to Me, all who are weary and heavy-laden, and I will give you rest. Take My yoke upon you, and learn from Me, for I am gentle and humble in heart; and you shall find rest for your souls. For My yoke is easy, and My load is light." (Matthew 11:28-30) I can live with it the way it is but it would be nice to automate the whole process. I reallu appreciate your time and assistance. Michael Reverend Burns, You are welcome. The solution you seek for your first question doesn't really not require a macro. If I understand you correctly, you have the habit of pressing enter twice to place a blank paragraph between your current text paragraph and a new text paragraph and then you want to format that empty paragraph with font size 6. A better approach would be to create a paragraph style for your sermon notes that uses Times New Roman 16 pt and 6 points of space after the paragraph. Hit the enter key once to start a new paragraph. However, if you really want to stick with your current method you could use: Sub ScratchMacro() Dim oPar As Paragraph For Each oPar In ActiveDocument.Range.Paragraphs If Len(oPar.Range.Text) = 1 Then oPar.Range.Font.Size = 8 End If Next oPar End Sub For the second request you could use something like this: Sub ScratchKeyWordMacro() Dim oRNg As Word.Range Dim i As Long Dim pWord As String Set oRNg = ActiveDocument.Range pWord = InputBox("Enter the keyword:", "Key Word") With oRNg.Find .Text = pWord .MatchCase = False .MatchWholeWord = True While .Execute i = i + 1 oRNg.Collapse wdCollapseEnd Wend End With Set oRNg = ActiveDocument.Bookmarks("Keyword").Range oRNg.Text = "Keyword for today, " & pWord & ", is Used " & i & " Times" ActiveDocument.Bookmarks.Add "Keyword", oRNg End Sub Use the Ribbon Insert Tab, Links Group, Bookmarks control to insert a bookmark exactly where you want the results to appear. Name the bookmark "Keyword" Good luck. Greg Maxey - Word MVP My web site http://gregmaxey.mvps.org Word MVP web site http://word.mvps.org "Rev. Michael L. Burns" wrote in message . com... Hello Greg, Thanks for the macro Help. I'll give it a try when I get back ri rhe office on Tuesday. Could I impose on you again for help with two more macros that would make my work simpler? First, because of failing eyesite I have set my default font and font size on all documents to Times Romans, 16pt which makes my notes very readable. However, I routinely go through my completed documents and change the font size between paragraphs to 6pt. Can a macro be made to do this automaticully? Second, when teaching a class or preaching, I have for years picked a key word from my notes and encouraged the children (although I have found the adults get involved as well) to count how often I use the word in my message or lesson. I then give the child who comes the closest to the key word count in my manuscript a prize, usually a candy bar or the likes. This had greatly incread how much the children, and even the adults, pay attention. Prior to upgrading from Word 2000 to Word 2007 I used a macro that someone, I've forgotten who, made for me that would open a dialog box that would ask for the key word and then scan the document and give me a total of how many times that word was used in the notes. However, I no longer have the macro (forgot to save the code) when I did a clean install on my system at the same time I updated to Office 2007. Could you help in this macro as well with one change if it possible? After entering the key word in the dialog box and having the macro scan my document for the times the key word is used, instead of displaying the total count in a message box like the old macro used to, if possible I'd like to have the macro incert a line in my document that would say something like "Key Word for Today, XXX, is Used YYY Times" where XXX is the Key Word and YYY is the number of times it is used. I always start my notes with three lines, centered in bold print, which are the sermon or lesson title, the text under study, and the date. I'd like the line inserted in bold print and centered after the date which would mean at the fourth line. If this could be done, I'd really appreaciate it. If not I could live with the way the old macro worked. I know this is a lot to ask but I'm dumber than an oyster win it comes to coding macros. Any help would be greatly appreciated and thanks again for the italicised quote macro. Pastor Burns Rev. Burns: Sub WordsInQuotes() Dim myRange As Range Dim myString As String Set myRange = ActiveDocument.Range With myRange Do While .Find.Execute(FindText:="[^0147^01486^34][A-Za-z]{1,}[^0147^01486^34 ]" , _ MatchWildcards:=True, Wrap:=wdFindStop, Forward:=True) = True '.MoveStart Unit:=wdCharacter, Count:=1 '.MoveEnd Unit:=wdCharacter, Count:=-1 .Font.Italic = True .Collapse Direction:=wdCollapseEnd Loop End With Set myRange = Nothing End Sub The code includes the quotation marks making them italic as well. I you just want the text (i.e., leave the marks themselves alone) then remove the stet marks ' from the the two Move lines. |
#12
Posted to microsoft.public.word.newusers
|
|||
|
|||
Macro Help Needed
Whatever works
-- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org Greg Maxey wrote: Pastor Burns, It was a little late last night so I omitted some of the bells and whistles that my friend Graham later added. He and I use a little different style so I would have approached the possibility of the missing bookmark as follows: Sub ScratchKeyWordMacro() Dim oRng As Word.Range Dim i As Long Dim oBMs As Bookmarks Dim pWord As String Dim sNum As String Set oBMs = ActiveDocument.Bookmarks On Error Resume Next Set oRng = oBMs("Keyword").Range If Err.Number = 5941 Then 'Error is produced if BM doesn't exist. Set oRng = Selection.Range oBMs.Add "Keyword", oRng End If On Error GoTo 0 Set oRng = ActiveDocument.Range pWord = InputBox("Enter the keyword:", "Key Word") With oRng.Find .Text = pWord .MatchCase = False .MatchWholeWord = True While .Execute i = i + 1 oRng.Collapse wdCollapseEnd Wend End With pWord = Chr(34) & UCase(pWord) & Chr(34) Select Case i Case Is = 1 sNum = "once" Case Is = 2 sNum = "twice" Case Else sNum = i & " times" End Select Set oRng = ActiveDocument.Bookmarks("Keyword").Range oRng.Text = "Keyword for today, " & pWord & ", is used " & sNum & vbCr oRng.ParagraphFormat.SpaceAfter = 16 ActiveDocument.Bookmarks.Add "Keyword", oRng End Sub With either code, all you have to do is put your cursor where you want the statistic to appear and run the code. While not impossible, it could be a little difficult to place the bookmark for you automatically because of your practice of using empty paragraphs. I think a reasonable approach would be for you to create a template for your notes that already contains the bookmark at the proper location whenever you start a new document based on the template. Again it was late when I made the modification to the quote macro. It is supposed to work (and now does) regardless if yo want the qoute marks themselves included in the italic format or left as is. Unsetting the three lines belong excludes the marks. Leaving them to run includes the marks. Sub WordsInQuotes() Dim myRange As Range Dim myString As String Set myRange = ActiveDocument.Range With myRange.Find .Text = "[^0147^01486^34]*[^0147^01486^34]" .MatchWildcards = True .Wrap = wdFindStop .Forward = True While .Execute With myRange '.MoveStart Unit:=wdCharacter, Count:=1 '.MoveEnd Unit:=wdCharacter, Count:=-1 .Font.Italic = True .Collapse Direction:=wdCollapseEnd '.MoveStart Unit:=wdCharacter, Count:=1 End With Wend End With Set myRange = Nothing End Sub "Rev. Michael L. Burns" wrote in message . com... Hello Greg, The Scratch macro works great but I may eventually creat a style as you suggested as soon as I learn a little more. The Keyword macro works great with one exception. Is there a way to have it add a blank line after the message is inserted at the bookmark? Right now, unless I manually insert two blank lines between the date and the body of the document the tope of the document looks something like this: Check Your Baggage Here Matthew 11:28-30 August 22, 2009 Keyword for today, Baggage, is Used 36 Times Come to Me, all who are weary and heavy-laden, and I will give you rest. Take My yoke upon you, and learn from Me, for I am gentle and humble in heart; and you shall find rest for your souls. For My yoke is easy, and My load is light." (Matthew 11:28-30) I can live with it the way it is but it would be nice to automate the whole process. I reallu appreciate your time and assistance. Michael Reverend Burns, You are welcome. The solution you seek for your first question doesn't really not require a macro. If I understand you correctly, you have the habit of pressing enter twice to place a blank paragraph between your current text paragraph and a new text paragraph and then you want to format that empty paragraph with font size 6. A better approach would be to create a paragraph style for your sermon notes that uses Times New Roman 16 pt and 6 points of space after the paragraph. Hit the enter key once to start a new paragraph. However, if you really want to stick with your current method you could use: Sub ScratchMacro() Dim oPar As Paragraph For Each oPar In ActiveDocument.Range.Paragraphs If Len(oPar.Range.Text) = 1 Then oPar.Range.Font.Size = 8 End If Next oPar End Sub For the second request you could use something like this: Sub ScratchKeyWordMacro() Dim oRNg As Word.Range Dim i As Long Dim pWord As String Set oRNg = ActiveDocument.Range pWord = InputBox("Enter the keyword:", "Key Word") With oRNg.Find .Text = pWord .MatchCase = False .MatchWholeWord = True While .Execute i = i + 1 oRNg.Collapse wdCollapseEnd Wend End With Set oRNg = ActiveDocument.Bookmarks("Keyword").Range oRNg.Text = "Keyword for today, " & pWord & ", is Used " & i & " Times" ActiveDocument.Bookmarks.Add "Keyword", oRNg End Sub Use the Ribbon Insert Tab, Links Group, Bookmarks control to insert a bookmark exactly where you want the results to appear. Name the bookmark "Keyword" Good luck. Greg Maxey - Word MVP My web site http://gregmaxey.mvps.org Word MVP web site http://word.mvps.org "Rev. Michael L. Burns" wrote in message . com... Hello Greg, Thanks for the macro Help. I'll give it a try when I get back ri rhe office on Tuesday. Could I impose on you again for help with two more macros that would make my work simpler? First, because of failing eyesite I have set my default font and font size on all documents to Times Romans, 16pt which makes my notes very readable. However, I routinely go through my completed documents and change the font size between paragraphs to 6pt. Can a macro be made to do this automaticully? Second, when teaching a class or preaching, I have for years picked a key word from my notes and encouraged the children (although I have found the adults get involved as well) to count how often I use the word in my message or lesson. I then give the child who comes the closest to the key word count in my manuscript a prize, usually a candy bar or the likes. This had greatly incread how much the children, and even the adults, pay attention. Prior to upgrading from Word 2000 to Word 2007 I used a macro that someone, I've forgotten who, made for me that would open a dialog box that would ask for the key word and then scan the document and give me a total of how many times that word was used in the notes. However, I no longer have the macro (forgot to save the code) when I did a clean install on my system at the same time I updated to Office 2007. Could you help in this macro as well with one change if it possible? After entering the key word in the dialog box and having the macro scan my document for the times the key word is used, instead of displaying the total count in a message box like the old macro used to, if possible I'd like to have the macro incert a line in my document that would say something like "Key Word for Today, XXX, is Used YYY Times" where XXX is the Key Word and YYY is the number of times it is used. I always start my notes with three lines, centered in bold print, which are the sermon or lesson title, the text under study, and the date. I'd like the line inserted in bold print and centered after the date which would mean at the fourth line. If this could be done, I'd really appreaciate it. If not I could live with the way the old macro worked. I know this is a lot to ask but I'm dumber than an oyster win it comes to coding macros. Any help would be greatly appreciated and thanks again for the italicised quote macro. Pastor Burns Rev. Burns: Sub WordsInQuotes() Dim myRange As Range Dim myString As String Set myRange = ActiveDocument.Range With myRange Do While .Find.Execute(FindText:="[^0147^01486^34][A-Za-z]{1,}[^0147^01486^34 ]" , _ MatchWildcards:=True, Wrap:=wdFindStop, Forward:=True) = True '.MoveStart Unit:=wdCharacter, Count:=1 '.MoveEnd Unit:=wdCharacter, Count:=-1 .Font.Italic = True .Collapse Direction:=wdCollapseEnd Loop End With Set myRange = Nothing End Sub The code includes the quotation marks making them italic as well. I you just want the text (i.e., leave the marks themselves alone) then remove the stet marks ' from the the two Move lines. |
#13
Posted to microsoft.public.word.newusers
|
|||
|
|||
Macro Help Needed
Graham,
Yes of course. Just showing the difference is styles. Some subtle some blunt ;-) Graham Mayor wrote: Whatever works Greg Maxey wrote: Pastor Burns, It was a little late last night so I omitted some of the bells and whistles that my friend Graham later added. He and I use a little different style so I would have approached the possibility of the missing bookmark as follows: Sub ScratchKeyWordMacro() Dim oRng As Word.Range Dim i As Long Dim oBMs As Bookmarks Dim pWord As String Dim sNum As String Set oBMs = ActiveDocument.Bookmarks On Error Resume Next Set oRng = oBMs("Keyword").Range If Err.Number = 5941 Then 'Error is produced if BM doesn't exist. Set oRng = Selection.Range oBMs.Add "Keyword", oRng End If On Error GoTo 0 Set oRng = ActiveDocument.Range pWord = InputBox("Enter the keyword:", "Key Word") With oRng.Find .Text = pWord .MatchCase = False .MatchWholeWord = True While .Execute i = i + 1 oRng.Collapse wdCollapseEnd Wend End With pWord = Chr(34) & UCase(pWord) & Chr(34) Select Case i Case Is = 1 sNum = "once" Case Is = 2 sNum = "twice" Case Else sNum = i & " times" End Select Set oRng = ActiveDocument.Bookmarks("Keyword").Range oRng.Text = "Keyword for today, " & pWord & ", is used " & sNum & vbCr oRng.ParagraphFormat.SpaceAfter = 16 ActiveDocument.Bookmarks.Add "Keyword", oRng End Sub With either code, all you have to do is put your cursor where you want the statistic to appear and run the code. While not impossible, it could be a little difficult to place the bookmark for you automatically because of your practice of using empty paragraphs. I think a reasonable approach would be for you to create a template for your notes that already contains the bookmark at the proper location whenever you start a new document based on the template. Again it was late when I made the modification to the quote macro. It is supposed to work (and now does) regardless if yo want the qoute marks themselves included in the italic format or left as is. Unsetting the three lines belong excludes the marks. Leaving them to run includes the marks. Sub WordsInQuotes() Dim myRange As Range Dim myString As String Set myRange = ActiveDocument.Range With myRange.Find .Text = "[^0147^01486^34]*[^0147^01486^34]" .MatchWildcards = True .Wrap = wdFindStop .Forward = True While .Execute With myRange '.MoveStart Unit:=wdCharacter, Count:=1 '.MoveEnd Unit:=wdCharacter, Count:=-1 .Font.Italic = True .Collapse Direction:=wdCollapseEnd '.MoveStart Unit:=wdCharacter, Count:=1 End With Wend End With Set myRange = Nothing End Sub "Rev. Michael L. Burns" wrote in message . com... Hello Greg, The Scratch macro works great but I may eventually creat a style as you suggested as soon as I learn a little more. The Keyword macro works great with one exception. Is there a way to have it add a blank line after the message is inserted at the bookmark? Right now, unless I manually insert two blank lines between the date and the body of the document the tope of the document looks something like this: Check Your Baggage Here Matthew 11:28-30 August 22, 2009 Keyword for today, Baggage, is Used 36 Times Come to Me, all who are weary and heavy-laden, and I will give you rest. Take My yoke upon you, and learn from Me, for I am gentle and humble in heart; and you shall find rest for your souls. For My yoke is easy, and My load is light." (Matthew 11:28-30) I can live with it the way it is but it would be nice to automate the whole process. I reallu appreciate your time and assistance. Michael Reverend Burns, You are welcome. The solution you seek for your first question doesn't really not require a macro. If I understand you correctly, you have the habit of pressing enter twice to place a blank paragraph between your current text paragraph and a new text paragraph and then you want to format that empty paragraph with font size 6. A better approach would be to create a paragraph style for your sermon notes that uses Times New Roman 16 pt and 6 points of space after the paragraph. Hit the enter key once to start a new paragraph. However, if you really want to stick with your current method you could use: Sub ScratchMacro() Dim oPar As Paragraph For Each oPar In ActiveDocument.Range.Paragraphs If Len(oPar.Range.Text) = 1 Then oPar.Range.Font.Size = 8 End If Next oPar End Sub For the second request you could use something like this: Sub ScratchKeyWordMacro() Dim oRNg As Word.Range Dim i As Long Dim pWord As String Set oRNg = ActiveDocument.Range pWord = InputBox("Enter the keyword:", "Key Word") With oRNg.Find .Text = pWord .MatchCase = False .MatchWholeWord = True While .Execute i = i + 1 oRNg.Collapse wdCollapseEnd Wend End With Set oRNg = ActiveDocument.Bookmarks("Keyword").Range oRNg.Text = "Keyword for today, " & pWord & ", is Used " & i & " Times" ActiveDocument.Bookmarks.Add "Keyword", oRNg End Sub Use the Ribbon Insert Tab, Links Group, Bookmarks control to insert a bookmark exactly where you want the results to appear. Name the bookmark "Keyword" Good luck. Greg Maxey - Word MVP My web site http://gregmaxey.mvps.org Word MVP web site http://word.mvps.org "Rev. Michael L. Burns" wrote in message . com... Hello Greg, Thanks for the macro Help. I'll give it a try when I get back ri rhe office on Tuesday. Could I impose on you again for help with two more macros that would make my work simpler? First, because of failing eyesite I have set my default font and font size on all documents to Times Romans, 16pt which makes my notes very readable. However, I routinely go through my completed documents and change the font size between paragraphs to 6pt. Can a macro be made to do this automaticully? Second, when teaching a class or preaching, I have for years picked a key word from my notes and encouraged the children (although I have found the adults get involved as well) to count how often I use the word in my message or lesson. I then give the child who comes the closest to the key word count in my manuscript a prize, usually a candy bar or the likes. This had greatly incread how much the children, and even the adults, pay attention. Prior to upgrading from Word 2000 to Word 2007 I used a macro that someone, I've forgotten who, made for me that would open a dialog box that would ask for the key word and then scan the document and give me a total of how many times that word was used in the notes. However, I no longer have the macro (forgot to save the code) when I did a clean install on my system at the same time I updated to Office 2007. Could you help in this macro as well with one change if it possible? After entering the key word in the dialog box and having the macro scan my document for the times the key word is used, instead of displaying the total count in a message box like the old macro used to, if possible I'd like to have the macro incert a line in my document that would say something like "Key Word for Today, XXX, is Used YYY Times" where XXX is the Key Word and YYY is the number of times it is used. I always start my notes with three lines, centered in bold print, which are the sermon or lesson title, the text under study, and the date. I'd like the line inserted in bold print and centered after the date which would mean at the fourth line. If this could be done, I'd really appreaciate it. If not I could live with the way the old macro worked. I know this is a lot to ask but I'm dumber than an oyster win it comes to coding macros. Any help would be greatly appreciated and thanks again for the italicised quote macro. Pastor Burns Rev. Burns: Sub WordsInQuotes() Dim myRange As Range Dim myString As String Set myRange = ActiveDocument.Range With myRange Do While .Find.Execute(FindText:="[^0147^01486^34][A-Za-z]{1,}[^0147^01486^34 ]" , _ MatchWildcards:=True, Wrap:=wdFindStop, Forward:=True) = True '.MoveStart Unit:=wdCharacter, Count:=1 '.MoveEnd Unit:=wdCharacter, Count:=-1 .Font.Italic = True .Collapse Direction:=wdCollapseEnd Loop End With Set myRange = Nothing End Sub The code includes the quotation marks making them italic as well. I you just want the text (i.e., leave the marks themselves alone) then remove the stet marks ' from the the two Move lines. -- Greg Maxey - Word MVP My web site http://gregmaxey.mvps.org Word MVP web site http://word.mvps.org |
#14
Posted to microsoft.public.word.newusers
|
|||
|
|||
Macro Help Needed
Hello Graham,
Just a short note to say thanks for your help. The macro does what I want. Much appreciated, Michael The keyword macro below includes your request for more space. I have taken the liberty of adding a routine to check for the presence of the bookmark and if it is not in the document it will be created at the cursor. Sub ScratchKeyWordMacro() Dim oRNg As Word.Range Dim i As Long Dim bExists As Boolean Dim vBM As Variant Dim oBMs As Bookmarks Dim pWord As String Dim sNum As String Set oRNg = ActiveDocument.Range Set oBMs = ActiveDocument.Bookmarks For Each vBM In oBMs If vBM.name = "Keyword" Then bExists = True Exit For End If Next vBM If bExists = False Then ActiveDocument.Bookmarks.Add "Keyword", Selection.Range End If pWord = InputBox("Enter the keyword:", "Key Word") With oRNg.Find .Text = pWord .MatchCase = False .MatchWholeWord = True While .Execute i = i + 1 oRNg.Collapse wdCollapseEnd Wend End With pWord = Chr(34) & UCase(pWord) & Chr(34) Select Case i Case Is = 1 sNum = "once" Case Is = 2 sNum = "twice" Case Else sNum = i & " times" End Select Set oRNg = ActiveDocument.Bookmarks("Keyword").Range oRNg.Text = "Keyword for today, " & pWord & ", is used " & sNum & vbCr oRNg.ParagraphFormat.SpaceAfter = 16 ActiveDocument.Bookmarks.Add "Keyword", oRNg End Sub My web site www.gmayor.com Word MVP web site http://word.mvps.org Rev. Michael L. Burns wrote: Hello Greg, The Scratch macro works great but I may eventually creat a style as you suggested as soon as I learn a little more. The Keyword macro works great with one exception. Is there a way to have it add a blank line after the message is inserted at the bookmark? Right now, unless I manually insert two blank lines between the date and the body of the document the tope of the document looks something like this: Check Your Baggage Here Matthew 11:28-30 August 22, 2009 Keyword for today, Baggage, is Used 36 Times Come to Me, all who are weary and heavy-laden, and I will give you rest. Take My yoke upon you, and learn from Me, for I am gentle and humble in heart; and you shall find rest for your souls. For My yoke is easy, and My load is light." (Matthew 11:28-30) I can live with it the way it is but it would be nice to automate the whole process. I reallu appreciate your time and assistance. Michael Reverend Burns, You are welcome. The solution you seek for your first question doesn't really not require a macro. If I understand you correctly, you have the habit of pressing enter twice to place a blank paragraph between your current text paragraph and a new text paragraph and then you want to format that empty paragraph with font size 6. A better approach would be to create a paragraph style for your sermon notes that uses Times New Roman 16 pt and 6 points of space after the paragraph. Hit the enter key once to start a new paragraph. However, if you really want to stick with your current method you could use: Sub ScratchMacro() Dim oPar As Paragraph For Each oPar In ActiveDocument.Range.Paragraphs If Len(oPar.Range.Text) = 1 Then oPar.Range.Font.Size = 8 End If Next oPar End Sub For the second request you could use something like this: Sub ScratchKeyWordMacro() Dim oRNg As Word.Range Dim i As Long Dim pWord As String Set oRNg = ActiveDocument.Range pWord = InputBox("Enter the keyword:", "Key Word") With oRNg.Find .Text = pWord .MatchCase = False .MatchWholeWord = True While .Execute i = i + 1 oRNg.Collapse wdCollapseEnd Wend End With Set oRNg = ActiveDocument.Bookmarks("Keyword").Range oRNg.Text = "Keyword for today, " & pWord & ", is Used " & i & " Times" ActiveDocument.Bookmarks.Add "Keyword", oRNg End Sub Use the Ribbon Insert Tab, Links Group, Bookmarks control to insert a bookmark exactly where you want the results to appear. Name the bookmark "Keyword" Good luck. Greg Maxey - Word MVP My web site http://gregmaxey.mvps.org Word MVP web site http://word.mvps.org "Rev. Michael L. Burns" wrote in message . com... Hello Greg, Thanks for the macro Help. I'll give it a try when I get back ri rhe office on Tuesday. Could I impose on you again for help with two more macros that would make my work simpler? First, because of failing eyesite I have set my default font and font size on all documents to Times Romans, 16pt which makes my notes very readable. However, I routinely go through my completed documents and change the font size between paragraphs to 6pt. Can a macro be made to do this automaticully? Second, when teaching a class or preaching, I have for years picked a key word from my notes and encouraged the children (although I have found the adults get involved as well) to count how often I use the word in my message or lesson. I then give the child who comes the closest to the key word count in my manuscript a prize, usually a candy bar or the likes. This had greatly incread how much the children, and even the adults, pay attention. Prior to upgrading from Word 2000 to Word 2007 I used a macro that someone, I've forgotten who, made for me that would open a dialog box that would ask for the key word and then scan the document and give me a total of how many times that word was used in the notes. However, I no longer have the macro (forgot to save the code) when I did a clean install on my system at the same time I updated to Office 2007. Could you help in this macro as well with one change if it possible? After entering the key word in the dialog box and having the macro scan my document for the times the key word is used, instead of displaying the total count in a message box like the old macro used to, if possible I'd like to have the macro incert a line in my document that would say something like "Key Word for Today, XXX, is Used YYY Times" where XXX is the Key Word and YYY is the number of times it is used. I always start my notes with three lines, centered in bold print, which are the sermon or lesson title, the text under study, and the date. I'd like the line inserted in bold print and centered after the date which would mean at the fourth line. If this could be done, I'd really appreaciate it. If not I could live with the way the old macro worked. I know this is a lot to ask but I'm dumber than an oyster win it comes to coding macros. Any help would be greatly appreciated and thanks again for the italicised quote macro. Pastor Burns Rev. Burns: Sub WordsInQuotes() Dim myRange As Range Dim myString As String Set myRange = ActiveDocument.Range With myRange Do While .Find.Execute(FindText:="[^0147^01486^34][A-Za-z]{1,}[^0147^01486^ 34 ]" , _ MatchWildcards:=True, Wrap:=wdFindStop, Forward:=True) = True '.MoveStart Unit:=wdCharacter, Count:=1 '.MoveEnd Unit:=wdCharacter, Count:=-1 .Font.Italic = True .Collapse Direction:=wdCollapseEnd Loop End With Set myRange = Nothing End Sub The code includes the quotation marks making them italic as well. I you just want the text (i.e., leave the marks themselves alone) then remove the stet marks ' from the the two Move lines. |
#15
Posted to microsoft.public.word.newusers
|
|||
|
|||
Macro Help Needed
Hello Greg,
Thanks again for your time and patience. Both the WordsInQuotrs and KeyWord macro's seem to be working great now. Thank you ever so much, Michael Pastor Burns, It was a little late last night so I omitted some of the bells and whistles that my friend Graham later added. He and I use a little different style so I would have approached the possibility of the missing bookmark as follows: Sub ScratchKeyWordMacro() Dim oRng As Word.Range Dim i As Long Dim oBMs As Bookmarks Dim pWord As String Dim sNum As String Set oBMs = ActiveDocument.Bookmarks On Error Resume Next Set oRng = oBMs("Keyword").Range If Err.Number = 5941 Then 'Error is produced if BM doesn't exist. Set oRng = Selection.Range oBMs.Add "Keyword", oRng End If On Error GoTo 0 Set oRng = ActiveDocument.Range pWord = InputBox("Enter the keyword:", "Key Word") With oRng.Find .Text = pWord .MatchCase = False .MatchWholeWord = True While .Execute i = i + 1 oRng.Collapse wdCollapseEnd Wend End With pWord = Chr(34) & UCase(pWord) & Chr(34) Select Case i Case Is = 1 sNum = "once" Case Is = 2 sNum = "twice" Case Else sNum = i & " times" End Select Set oRng = ActiveDocument.Bookmarks("Keyword").Range oRng.Text = "Keyword for today, " & pWord & ", is used " & sNum & vbCr oRng.ParagraphFormat.SpaceAfter = 16 ActiveDocument.Bookmarks.Add "Keyword", oRng End Sub With either code, all you have to do is put your cursor where you want the statistic to appear and run the code. While not impossible, it could be a little difficult to place the bookmark for you automatically because of your practice of using empty paragraphs. I think a reasonable approach would be for you to create a template for your notes that already contains the bookmark at the proper location whenever you start a new document based on the template. Again it was late when I made the modification to the quote macro. It is supposed to work (and now does) regardless if yo want the qoute marks themselves included in the italic format or left as is. Unsetting the three lines belong excludes the marks. Leaving them to run includes the marks. Sub WordsInQuotes() Dim myRange As Range Dim myString As String Set myRange = ActiveDocument.Range With myRange.Find .Text = "[^0147^01486^34]*[^0147^01486^34]" .MatchWildcards = True .Wrap = wdFindStop .Forward = True While .Execute With myRange '.MoveStart Unit:=wdCharacter, Count:=1 '.MoveEnd Unit:=wdCharacter, Count:=-1 .Font.Italic = True .Collapse Direction:=wdCollapseEnd '.MoveStart Unit:=wdCharacter, Count:=1 End With Wend End With Set myRange = Nothing End Sub My web site http://gregmaxey.mvps.org Word MVP web site http://word.mvps.org "Rev. Michael L. Burns" wrote in message . com... Hello Greg, The Scratch macro works great but I may eventually creat a style as you suggested as soon as I learn a little more. The Keyword macro works great with one exception. Is there a way to have it add a blank line after the message is inserted at the bookmark? Right now, unless I manually insert two blank lines between the date and the body of the document the tope of the document looks something like this: Check Your Baggage Here Matthew 11:28-30 August 22, 2009 Keyword for today, Baggage, is Used 36 Times Come to Me, all who are weary and heavy-laden, and I will give you rest. Take My yoke upon you, and learn from Me, for I am gentle and humble in heart; and you shall find rest for your souls. For My yoke is easy, and My load is light." (Matthew 11:28-30) I can live with it the way it is but it would be nice to automate the whole process. I reallu appreciate your time and assistance. Michael Reverend Burns, You are welcome. The solution you seek for your first question doesn't really not require a macro. If I understand you correctly, you have the habit of pressing enter twice to place a blank paragraph between your current text paragraph and a new text paragraph and then you want to format that empty paragraph with font size 6. A better approach would be to create a paragraph style for your sermon notes that uses Times New Roman 16 pt and 6 points of space after the paragraph. Hit the enter key once to start a new paragraph. However, if you really want to stick with your current method you could use: Sub ScratchMacro() Dim oPar As Paragraph For Each oPar In ActiveDocument.Range.Paragraphs If Len(oPar.Range.Text) = 1 Then oPar.Range.Font.Size = 8 End If Next oPar End Sub For the second request you could use something like this: Sub ScratchKeyWordMacro() Dim oRNg As Word.Range Dim i As Long Dim pWord As String Set oRNg = ActiveDocument.Range pWord = InputBox("Enter the keyword:", "Key Word") With oRNg.Find .Text = pWord .MatchCase = False .MatchWholeWord = True While .Execute i = i + 1 oRNg.Collapse wdCollapseEnd Wend End With Set oRNg = ActiveDocument.Bookmarks("Keyword").Range oRNg.Text = "Keyword for today, " & pWord & ", is Used " & i & " Times" ActiveDocument.Bookmarks.Add "Keyword", oRNg End Sub Use the Ribbon Insert Tab, Links Group, Bookmarks control to insert a bookmark exactly where you want the results to appear. Name the bookmark "Keyword" Good luck. Greg Maxey - Word MVP My web site http://gregmaxey.mvps.org Word MVP web site http://word.mvps.org "Rev. Michael L. Burns" wrote in message . com... Hello Greg, Thanks for the macro Help. I'll give it a try when I get back ri rhe office on Tuesday. Could I impose on you again for help with two more macros that would make my work simpler? First, because of failing eyesite I have set my default font and font size on all documents to Times Romans, 16pt which makes my notes very readable. However, I routinely go through my completed documents and change the font size between paragraphs to 6pt. Can a macro be made to do this automaticully? Second, when teaching a class or preaching, I have for years picked a key word from my notes and encouraged the children (although I have found the adults get involved as well) to count how often I use the word in my message or lesson. I then give the child who comes the closest to the key word count in my manuscript a prize, usually a candy bar or the likes. This had greatly incread how much the children, and even the adults, pay attention. Prior to upgrading from Word 2000 to Word 2007 I used a macro that someone, I've forgotten who, made for me that would open a dialog box that would ask for the key word and then scan the document and give me a total of how many times that word was used in the notes. However, I no longer have the macro (forgot to save the code) when I did a clean install on my system at the same time I updated to Office 2007. Could you help in this macro as well with one change if it possible? After entering the key word in the dialog box and having the macro scan my document for the times the key word is used, instead of displaying the total count in a message box like the old macro used to, if possible I'd like to have the macro incert a line in my document that would say something like "Key Word for Today, XXX, is Used YYY Times" where XXX is the Key Word and YYY is the number of times it is used. I always start my notes with three lines, centered in bold print, which are the sermon or lesson title, the text under study, and the date. I'd like the line inserted in bold print and centered after the date which would mean at the fourth line. If this could be done, I'd really appreaciate it. If not I could live with the way the old macro worked. I know this is a lot to ask but I'm dumber than an oyster win it comes to coding macros. Any help would be greatly appreciated and thanks again for the italicised quote macro. Pastor Burns Rev. Burns: Sub WordsInQuotes() Dim myRange As Range Dim myString As String Set myRange = ActiveDocument.Range With myRange Do While .Find.Execute(FindText:="[^0147^01486^34][A-Za-z]{1,}[^0147^01486^ 34 ]" , _ MatchWildcards:=True, Wrap:=wdFindStop, Forward:=True) = True '.MoveStart Unit:=wdCharacter, Count:=1 '.MoveEnd Unit:=wdCharacter, Count:=-1 .Font.Italic = True .Collapse Direction:=wdCollapseEnd Loop End With Set myRange = Nothing End Sub The code includes the quotation marks making them italic as well. I you just want the text (i.e., leave the marks themselves alone) then remove the stet marks ' from the the two Move lines. |
#16
Posted to microsoft.public.word.newusers
|
|||
|
|||
Macro Help Needed
Most of the work was Greg's, but you are welcome anyway
-- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org Rev. Michael L. Burns wrote: Hello Graham, Just a short note to say thanks for your help. The macro does what I want. Much appreciated, Michael The keyword macro below includes your request for more space. I have taken the liberty of adding a routine to check for the presence of the bookmark and if it is not in the document it will be created at the cursor. Sub ScratchKeyWordMacro() Dim oRNg As Word.Range Dim i As Long Dim bExists As Boolean Dim vBM As Variant Dim oBMs As Bookmarks Dim pWord As String Dim sNum As String Set oRNg = ActiveDocument.Range Set oBMs = ActiveDocument.Bookmarks For Each vBM In oBMs If vBM.name = "Keyword" Then bExists = True Exit For End If Next vBM If bExists = False Then ActiveDocument.Bookmarks.Add "Keyword", Selection.Range End If pWord = InputBox("Enter the keyword:", "Key Word") With oRNg.Find .Text = pWord .MatchCase = False .MatchWholeWord = True While .Execute i = i + 1 oRNg.Collapse wdCollapseEnd Wend End With pWord = Chr(34) & UCase(pWord) & Chr(34) Select Case i Case Is = 1 sNum = "once" Case Is = 2 sNum = "twice" Case Else sNum = i & " times" End Select Set oRNg = ActiveDocument.Bookmarks("Keyword").Range oRNg.Text = "Keyword for today, " & pWord & ", is used " & sNum & vbCr oRNg.ParagraphFormat.SpaceAfter = 16 ActiveDocument.Bookmarks.Add "Keyword", oRNg End Sub My web site www.gmayor.com Word MVP web site http://word.mvps.org Rev. Michael L. Burns wrote: Hello Greg, The Scratch macro works great but I may eventually creat a style as you suggested as soon as I learn a little more. The Keyword macro works great with one exception. Is there a way to have it add a blank line after the message is inserted at the bookmark? Right now, unless I manually insert two blank lines between the date and the body of the document the tope of the document looks something like this: Check Your Baggage Here Matthew 11:28-30 August 22, 2009 Keyword for today, Baggage, is Used 36 Times Come to Me, all who are weary and heavy-laden, and I will give you rest. Take My yoke upon you, and learn from Me, for I am gentle and humble in heart; and you shall find rest for your souls. For My yoke is easy, and My load is light." (Matthew 11:28-30) I can live with it the way it is but it would be nice to automate the whole process. I reallu appreciate your time and assistance. Michael Reverend Burns, You are welcome. The solution you seek for your first question doesn't really not require a macro. If I understand you correctly, you have the habit of pressing enter twice to place a blank paragraph between your current text paragraph and a new text paragraph and then you want to format that empty paragraph with font size 6. A better approach would be to create a paragraph style for your sermon notes that uses Times New Roman 16 pt and 6 points of space after the paragraph. Hit the enter key once to start a new paragraph. However, if you really want to stick with your current method you could use: Sub ScratchMacro() Dim oPar As Paragraph For Each oPar In ActiveDocument.Range.Paragraphs If Len(oPar.Range.Text) = 1 Then oPar.Range.Font.Size = 8 End If Next oPar End Sub For the second request you could use something like this: Sub ScratchKeyWordMacro() Dim oRNg As Word.Range Dim i As Long Dim pWord As String Set oRNg = ActiveDocument.Range pWord = InputBox("Enter the keyword:", "Key Word") With oRNg.Find .Text = pWord .MatchCase = False .MatchWholeWord = True While .Execute i = i + 1 oRNg.Collapse wdCollapseEnd Wend End With Set oRNg = ActiveDocument.Bookmarks("Keyword").Range oRNg.Text = "Keyword for today, " & pWord & ", is Used " & i & " Times" ActiveDocument.Bookmarks.Add "Keyword", oRNg End Sub Use the Ribbon Insert Tab, Links Group, Bookmarks control to insert a bookmark exactly where you want the results to appear. Name the bookmark "Keyword" Good luck. Greg Maxey - Word MVP My web site http://gregmaxey.mvps.org Word MVP web site http://word.mvps.org "Rev. Michael L. Burns" wrote in message . com... Hello Greg, Thanks for the macro Help. I'll give it a try when I get back ri rhe office on Tuesday. Could I impose on you again for help with two more macros that would make my work simpler? First, because of failing eyesite I have set my default font and font size on all documents to Times Romans, 16pt which makes my notes very readable. However, I routinely go through my completed documents and change the font size between paragraphs to 6pt. Can a macro be made to do this automaticully? Second, when teaching a class or preaching, I have for years picked a key word from my notes and encouraged the children (although I have found the adults get involved as well) to count how often I use the word in my message or lesson. I then give the child who comes the closest to the key word count in my manuscript a prize, usually a candy bar or the likes. This had greatly incread how much the children, and even the adults, pay attention. Prior to upgrading from Word 2000 to Word 2007 I used a macro that someone, I've forgotten who, made for me that would open a dialog box that would ask for the key word and then scan the document and give me a total of how many times that word was used in the notes. However, I no longer have the macro (forgot to save the code) when I did a clean install on my system at the same time I updated to Office 2007. Could you help in this macro as well with one change if it possible? After entering the key word in the dialog box and having the macro scan my document for the times the key word is used, instead of displaying the total count in a message box like the old macro used to, if possible I'd like to have the macro incert a line in my document that would say something like "Key Word for Today, XXX, is Used YYY Times" where XXX is the Key Word and YYY is the number of times it is used. I always start my notes with three lines, centered in bold print, which are the sermon or lesson title, the text under study, and the date. I'd like the line inserted in bold print and centered after the date which would mean at the fourth line. If this could be done, I'd really appreaciate it. If not I could live with the way the old macro worked. I know this is a lot to ask but I'm dumber than an oyster win it comes to coding macros. Any help would be greatly appreciated and thanks again for the italicised quote macro. Pastor Burns Rev. Burns: Sub WordsInQuotes() Dim myRange As Range Dim myString As String Set myRange = ActiveDocument.Range With myRange Do While .Find.Execute(FindText:="[^0147^01486^34][A-Za-z]{1,}[^0147^01486^ 34 ]" , _ MatchWildcards:=True, Wrap:=wdFindStop, Forward:=True) = True '.MoveStart Unit:=wdCharacter, Count:=1 '.MoveEnd Unit:=wdCharacter, Count:=-1 .Font.Italic = True .Collapse Direction:=wdCollapseEnd Loop End With Set myRange = Nothing End Sub The code includes the quotation marks making them italic as well. I you just want the text (i.e., leave the marks themselves alone) then remove the stet marks ' from the the two Move lines. |
Reply |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
macro needed | Microsoft Word Help | |||
Hide questions in a questionnaire - macro needed? | Microsoft Word Help | |||
Help needed w/booklet-printing macro, round 2 | Page Layout | |||
Help needed for Micrsoft Word Macro | Microsoft Word Help | |||
Table/Macro needed | New Users |