#1
|
|||
|
|||
Inserting Carriage Return
Hi all,
I have several documents where I would like to insert with a macro three (3) carriage returns (or hard returns--not sure about the correct wording) before the following words: Choice (a) Choice (b) Choice (c) Choice (d) As always, thank you for your cooperation and assistance. Cheers! |
#2
|
||||
|
||||
Manual formatting, like that you propose, simply perpetuates the problem. Create (or modify) a paragraph style to provide you with the spacing you want and apply it to the paragraphs.
The following will kill the two birds with one stone, by creating a suitable style in the document (if the name doesn't exist) to apply 36 points of space before each item. Code:
Sub Macro1() Dim oStyle As Style Dim bStyle As Boolean Dim oPara As Paragraph For Each oStyle In ActiveDocument.Styles If oStyle.NameLocal = "Extra Space" Then bStyle = True Exit For End If Next oStyle If Not bStyle Then ActiveDocument.Styles.Add name:="Extra Space", _ Type:=wdStyleTypeParagraph With ActiveDocument.Styles("Extra Space") .AutomaticallyUpdate = False .ParagraphFormat.SpaceBefore = 36 .NoSpaceBetweenParagraphsOfSameStyle = False End With End If For Each oPara In ActiveDocument.Paragraphs If oPara.Range.Text Like "Choice (*" Then oPara.Style = "Extra Space" End If Next oPara lbl_Exit: 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 |
#3
|
|||
|
|||
Try your macro but did not work. Don't know why. I tried something different. The following code was given to me by "MACROPOD". This code was from a previous posting by changing the following code:
.Text = " ([a-e].)" For: .Text = " (Answer)" HTML Code:
[PHP][/PHP] Sub DemoAnswer() Application.ScreenUpdating = False With ActiveDocument.Range .InsertBefore " " With .Find .ClearFormatting .Replacement.ClearFormatting .Forward = True .Wrap = wdFindContinue .Format = False .MatchWildcards = True .Text = ".([0-9]{1,3}.)" .Replacement.Text = ". \1" .Execute Replace:=wdReplaceAll .Text = " (Answer)" .Replacement.Text = "^p\1" .Execute Replace:=wdReplaceAll .Replacement.Style = "Strong" .Text = " ([0-9]{1,3}.)" .Execute Replace:=wdReplaceAll End With .Characters.First.Delete End With Application.ScreenUpdating = True End Sub My intention when I asked for a code was to see if there was a way to insert a carriage return with a macro. With a little modification to the above macro I was able to get what I want. Here is how the information looks before applying the macro: 1. (a) The requirement is to identify the categories of financial statement assertions. Answer (a) is correct because the professional standards establish financial statement assertions for account balances, classes of transactions and disclosures. Answer (b) is incorrect because financial statement assertions are established for disclosures. Answer (c) is incorrect because financial statement assertions are established for classes of transactions. Answer (d) is incorrect because financial statement assertions are established for both classes of transactions and disclosures. Here is how the information looks after applying the macro (which I like): 1. (a) The requirement is to identify the categories of financial statement assertions. Answer (a) is correct because the professional standards establish financial statement assertions for account balances, classes of transactions and disclosures. Answer (b) is incorrect because financial statement assertions are established for disclosures. Answer (c) is incorrect because financial statement assertions are established for classes of transactions. Answer (d) is incorrect because financial statement assertions are established for both classes of transactions and disclosures. The question is, is there any way to modify the macro so I can have more spaces between the answer choices. Here is how the information should looks like. 1. (a) The requirement is to identify the categories of financial statement assertions. Answer (a) is correct because the professional standards establish financial statement assertions for account balances, classes of transactions and disclosures. Answer (b) is incorrect because financial statement assertions are established for disclosures. Answer (c) is incorrect because financial statement assertions are established for classes of transactions. Answer (d) is incorrect because financial statement assertions are established for both classes of transactions and disclosures. Thank you all for your help! |
#4
|
|||
|
|||
Hi Greg,
When the text looks like this, your macro does not work. 1. (a) The requirement is to identify the categories of financial statement assertions. Answer (a) is correct because the professional standards establish financial statement assertions for account balances, classes of transactions and disclosures. Answer (b) is incorrect because financial statement assertions are established for disclosures. Answer (c) is incorrect because financial statement assertions are established for classes of transactions. Answer (d) is incorrect because financial statement assertions are established for both classes of transactions and disclosures But when the text is like this your macro is working: 1. (a) The requirement is to identify the categories of financial statement assertions. Answer (a) is correct because the professional standards establish financial statement assertions for account balances, classes of transactions and disclosures. Answer (b) is incorrect because financial statement assertions are established for disclosures. Answer (c) is incorrect because financial statement assertions are established for classes of transactions. Answer (d) is incorrect because financial statement assertions are established for both classes of transactions and disclosures. Great! I can work from here!!!! Thanks! |
#5
|
||||
|
||||
The original macro does not work, because what you are actually looking for is not what you said you were looking for. The macro looks for paragraphs that start with 'Choice (', whereas now you tell us that the paragraph begins with 'Answer ('.
Code:
For Each oPara In ActiveDocument.Paragraphs If oPara.Range.Text Like "Choice (*" Then oPara.Style = "Extra Space" End If Next oPara
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Plain Text Content Control - Losing Styling on Carriage Return | kintap | Word | 0 | 07-16-2014 12:43 PM |
stop carriage return or enter key in a table | Alaska1 | Word | 1 | 01-14-2013 08:48 AM |
Coding into a macro a carriage return | sinbad | Word VBA | 6 | 02-27-2012 03:51 AM |
Paragraph (carriage) return font size | revrossreddick | Word | 2 | 12-28-2011 01:33 PM |
Carriage Return Help | UCHelp | Word | 1 | 04-04-2010 10:11 PM |