Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 02-15-2015, 05:51 AM
rsrasc rsrasc is offline Inserting Carriage Return Windows 7 64bit Inserting Carriage Return Office 2010 64bit
Competent Performer
Inserting Carriage Return
 
Join Date: Mar 2014
Location: Germany
Posts: 148
rsrasc is on a distinguished road
Default 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!
Reply With Quote
  #2  
Old 02-15-2015, 06:34 AM
gmayor's Avatar
gmayor gmayor is offline Inserting Carriage Return Windows 7 64bit Inserting Carriage Return Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,106
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

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
Reply With Quote
  #3  
Old 02-15-2015, 10:57 AM
rsrasc rsrasc is offline Inserting Carriage Return Windows 7 64bit Inserting Carriage Return Office 2010 64bit
Competent Performer
Inserting Carriage Return
 
Join Date: Mar 2014
Location: Germany
Posts: 148
rsrasc is on a distinguished road
Default

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!
Reply With Quote
  #4  
Old 02-15-2015, 03:20 PM
rsrasc rsrasc is offline Inserting Carriage Return Windows 7 64bit Inserting Carriage Return Office 2010 64bit
Competent Performer
Inserting Carriage Return
 
Join Date: Mar 2014
Location: Germany
Posts: 148
rsrasc is on a distinguished road
Default

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!
Reply With Quote
  #5  
Old 02-15-2015, 11:23 PM
gmayor's Avatar
gmayor gmayor is offline Inserting Carriage Return Windows 7 64bit Inserting Carriage Return Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,106
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

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
Then you have added in a completely different set of criteria. with phrases that are in the same paragraph, which the code was never intended to address.
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
Reply



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
Inserting Carriage Return stop carriage return or enter key in a table Alaska1 Word 1 01-14-2013 08:48 AM
Inserting Carriage Return Coding into a macro a carriage return sinbad Word VBA 6 02-27-2012 03:51 AM
Inserting Carriage Return 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

Other Forums: Access Forums

All times are GMT -7. The time now is 11:59 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft