#1
|
|||
|
|||
A few macros or functions run in a single macro?
Hi everyone, I need to run multiple functions in a single macro. Let me tell you about it with an example:
1- Paul found it much easier to use a pencil for taking notes as he could .......... mistakes, which he made plenty of, very easily. A) type B) erase C) deter D) furnish E) release 2- You have to watch that market trader very ...........; otherwise, he will sneakily throw a few rotten oranges in amongst the good ones. A) closely B) secretly C) violently D) daringly E) placidly 3- The-Portuguese water dog is one of several.......... of dog used by fishermen around the world to retrieve lost nets and tackle from the water. A) series B) descriptions C) breeds D)races E) ranks I have a lot of test questions/entries like this. I want to make each question (without options) a single paragraph and make them bold. Also there is an empty line between some of the questions, but not all of them, so the macro should take care of it, too. Needless to say, the macro should do its job from the beginning to the end of a document. Currently I use a macro to make the questions bold, but this macro only make one paragraph/line of "A)", so I need to add a function to make the lines into a single paragraph. What I'm using right now: Code:
Sub root() ' ' root Makro ' ' Selection.Find.ClearFormatting Selection.GoTo What:=wdGoToHeading, Which:=wdGoToFirst With Selection.Find .Text = "A)" .Forward = True '.Wrap = wdFindContinue .Format = False .MatchCase = True .MatchWholeWord = True .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Do While Selection.Find.Execute If Selection.Find.Found = True Then Selection.MoveUp Unit:=wdParagraph, Count:=3, Extend:=wdExtend Selection.Font.Bold = wdToggle Selection.MoveDown Unit:=wdParagraph, Count:=2 End If Loop End Sub Last edited by pentagram_31; 10-27-2018 at 08:35 AM. Reason: I want to clarify sth. |
#2
|
||||
|
||||
Try:
Code:
Sub Demo() Application.ScreenUpdating = False With ActiveDocument.Range With .Find .ClearFormatting .Replacement.ClearFormatting .Forward = True .Wrap = wdFindContinue .Format = False .MatchWildcards = True .Text = "[^13]{1,}" .Replacement.Text = " " .Execute Replace:=wdReplaceAll .Text = "[ ]{2,}" .Replacement.Text = " " .Execute Replace:=wdReplaceAll .Text = "(<[0-9]{1,}[!0-9]@)([A-Z]\))" .Replacement.Text = "^p\1^p\2" .Execute Replace:=wdReplaceAll .Text = "(<[0-9]{1,}[!0-9]@) ^13" .Replacement.Text = "\1^l" .Replacement.Style = "Strong" .Execute Replace:=wdReplaceAll End With End With Application.ScreenUpdating = True End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
||||
|
||||
Based on your example the following should work
Code:
Sub Macro1() 'Graham Mayor - http://www.gmayor.com - Last updated - 28 Oct 2018 Dim orng As Range Set orng = ActiveDocument.Range orng.Font.Bold = True orng = Replace(orng, Chr(11), Chr(13)) orng = Replace(orng, Chr(13) & Chr(13), Chr(13)) With orng.Find Do While .Execute(FindText:="[0-9]{1,}-", MatchWildcards:=True) If orng.Start = orng.Paragraphs(1).Range.Start Then orng.MoveEndUntil ")" orng.End = orng.End - 2 orng.Select orng = Replace(orng, Chr(13), Chr(32)) orng = Replace(orng, Chr(32 & Chr(32)), Chr(32)) End If orng.Collapse 0 Loop End With Set orng = ActiveDocument.Range With orng.Find Do While .Execute(FindText:="A)", MatchWildcards:=False) If orng.Start = orng.Paragraphs(1).Range.Start Then orng.MoveEnd wdParagraph, 2 orng.End = orng.End - 1 orng = Replace(orng, Chr(13), Chr(32)) orng = Replace(orng, Chr(32 & Chr(32)), Chr(32)) orng.Font.Bold = False End If orng.Collapse 0 Loop End With lbl_Exit: Set orng = Nothing Exit Sub End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#4
|
|||
|
|||
Thanks for both of the answers! I'll try them when I'm on the computer and let you know.
|
#5
|
|||
|
|||
I tried both of your suggestions, but I got runtime error 5560 in both. In macropod's suggestion, the macro doesn't make any changes.
In gmayor's suggestion, in spite of the error, the macro makes ALL the characters bold. Quote:
|
#6
|
|||
|
|||
I guess I made a mistake while explaining my problem in the first post:
[QUOTE]Currently I use a macro to make the questions bold, but this macro only make one paragraph/line of "A)", so I need to add a function to make the lines into a single paragraph.[QUOTE] It should be : Currently I use a macro to make the questions bold, but this macro only make ONE paragraph/line UPSIDE of "A)", so I need to add a function to make the lines into a single paragraph. Maybe you have already understood what it meant by looking at the macro codes, but since your suggestions didn't work for me, I double-checked my first post. |
#7
|
|||
|
|||
@macropod, I got the same runtime error 5560 in this line
Quote:
|
#8
|
||||
|
||||
The code I posted works just fine with the sample data you posted. For example, it turns:
Quote:
Quote:
,} in the code with: ;}
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#9
|
|||
|
|||
Yes, your example is just what I need.
I've made the change in the code, but now I get the runtime error 5834 in this line: [QUOTE.Replacement.Style = "Strong"][/QUOTE] By the way, I'm using Turkish in my system. |
#10
|
||||
|
||||
Change:
"Strong" to: wdStyleStrong (without the quote characters)
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#11
|
|||
|
|||
Thank you for the quick reply, it means a lot to me!
I've made the change, now it works. The only thing is that it clears the styling of the bold part (it becomes times new roman, 12), but that's not a big deal, I can choose all and change the font manually as I like Thank you again for your help, master! |
#12
|
|||
|
|||
By the way, there should have been an empty line between each question, can we do that in the code? This is also my bad in the first post, sorry.
|
#13
|
|||
|
|||
gmayor's macro also worked after I changed ,} to ;}, but it doesn't delete extra empty spaces between words.
I'm going for macropod's macro because it runs faster and deletes the spaces between words, but the only problem is that it also deletes the empty lines between the questions. |
#14
|
|||
|
|||
one last touch maybe?
|
#15
|
||||
|
||||
Spaces between questions, like fonts, should be managed by the application of the appropriate Style definitions. Since we don't know exactly what you want or what Styles you're using, we're really not in a position to help.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
Tags |
macro multiple functions |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Infinite loops occurring in find and replace functions in word macro | Thefirstfish` | Word VBA | 5 | 04-06-2017 07:18 PM |
Why are my Macros combined into a single module? | Cyberseeker | Excel Programming | 1 | 04-02-2017 02:43 AM |
Creating a "super macro" with all kind of functions | Xanthopteryx | PowerPoint | 1 | 06-16-2016 01:38 AM |
what functions would this task use, format, macro ? etc | fremoy | Word | 2 | 02-16-2015 10:48 AM |
Macro to save to a single PDF | LukeExcelKid | Excel Programming | 4 | 11-17-2013 01:39 PM |