![]() |
#1
|
|||
|
|||
![]()
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 |
#2
|
||||
|
||||
![]()
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 |
#3
|
||||
|
||||
![]()
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] |
#4
|
||||
|
||||
![]()
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 |
#5
|
||||
|
||||
![]()
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] |
![]() |
|
![]() |
||||
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 |
![]() |
caesib | Word | 6 | 02-07-2014 12:37 AM |
![]() |
icloudy | Word | 1 | 12-09-2012 03:49 PM |
![]() |
bethtop | Word | 1 | 02-07-2012 12:21 PM |
![]() |
LeeFX | Word | 4 | 05-05-2011 05:53 PM |