Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 09-20-2014, 11:12 AM
butters149 butters149 is offline Word paragraph formatting Windows 8 Word paragraph formatting Office 2013
Novice
Word paragraph formatting
 
Join Date: Sep 2014
Posts: 3
butters149 is on a distinguished road
Default Word paragraph formatting

Hi,

I am kind of new to Word, but my work requires me to use Word a lot and I wish to familiarize myself with the macros to format my text to send out to emails. Say I have a text below and want to modify it how would I do it? I am not even sure of what function I would need. I am pretty sure I would need a few steps and placeholders? Do I need to learn visual basics?



05/06/15 Expense 1.00 56.00 56.00
A
B
C
D

But I want it to look like this:
05/06/15 Expense 1.00 (Billed $56.00 Reduced $56.00) A B C
Reply With Quote
  #2  
Old 09-20-2014, 10:02 PM
gmayor's Avatar
gmayor gmayor is offline Word paragraph formatting Windows 7 64bit Word paragraph formatting Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,138
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 ofgmayor has much to be proud of
Default

You can certainly reformat the text using a macro (which is probably the easiest approach) but learning vba programming is not going to take five minutes.

If you select the text and run the following macro it will be formatted as your example:
Code:
Sub Example()
Dim oRng As Range
Dim strText As String
Dim vText As Variant
    'set the selected text as a range
    Set oRng = Selection.Range
    'assign a text string to the range
    strText = oRng.Text
    'remove the paragraph breaks from the text string
    strText = Replace(strText, Chr(13), Chr(32))
    'split at the default character which is space
    vText = Split(strText)
    'Reassemble the string in the required format
    oRng.Text = vText(0) & Chr(32) & _
                vText(1) & Chr(32) & _
                vText(2) & Chr(32) & _
                "(Billed $" & vText(3) & _
                " Reduced $" & vText(4) & _
                ") " & vText(5) & Chr(32) & vText(6) & Chr(32) & _
                vText(7) & Chr(32) & vText(8)
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 09-21-2014, 02:46 AM
macropod's Avatar
macropod macropod is offline Word paragraph formatting Windows 7 64bit Word paragraph formatting Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,375
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

You could also do it with just a wildcard Find/Replace, where:
Find = ([0-9]{2}/[0-9]{2}/[0-9]{2} Expense [0-9.]@ )([0-9.]@ )([0-9.]{1,})[!^13]@^13(*)^13(*)^13(*)^13*^13
Replace = \1(Billed $\2Reduced $\3) \4 \5 \6^p
No VBA required.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #4  
Old 09-21-2014, 03:05 AM
gmayor's Avatar
gmayor gmayor is offline Word paragraph formatting Windows 7 64bit Word paragraph formatting Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,138
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 ofgmayor has much to be proud of
Default

That would work, but is it any easier?

Either way there is no simple solution, and to adapt either solution is going to require some study. For Wildcard replacement see http://www.gmayor.com/replace_using_wildcards.htm
__________________
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
  #5  
Old 09-21-2014, 07:02 AM
macropod's Avatar
macropod macropod is offline Word paragraph formatting Windows 7 64bit Word paragraph formatting Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,375
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

I could have simplified the Find expression, but I wanted to minimise the risk of false matches. For example:
Find = ([0-9]*Expense [! ]@ )([! ]@ )([! ]{1,})[!^13]@^13(*)^13(*)^13(*)^13*^13

The OP could even record either of these as a macro and end up with code that processes either the first instance stating from the insertion point or an entire document. As coded, your macro:
• does no validation that what is selected contains the right kind of data;
• requires the entire range to be selected (will fail if less than the required range is selected); and
• will only work with the first instance and is liable to blat anything extra that gets selected but shouldn't be processed,
(just me being picky)
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Formatting contents after Tab of continuous lines or formatting specific area of word pawii Word 1 05-12-2014 05:24 AM
Word paragraph formatting Formatting: Paragraph /line spacing problem caesib Word 6 02-07-2014 12:37 AM
Word paragraph formatting Narrow Paragraph to Wide Paragraph HELP icloudy Word 1 12-09-2012 03:49 PM
Word paragraph formatting word won't let me put more than one paragraph per page bethtop Word 1 02-07-2012 12:21 PM
Word paragraph formatting [Word 2007] How to hyperlink directly another word file chapter/paragraph/bookmark? LeeFX Word 4 05-05-2011 05:53 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 04:40 AM.


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