#1
|
|||
|
|||
Loop macro to adjust text formating within Word
Hi Guys,
Hoping you can help, I am trying to put together a macro that runs thru a word document and adjusts the spacing of the text on each line and stops. Currently I have managed to get this to work using the movedown command, but this method means that I have to copy the macro for each line I want the macro to run on, for example if I have 12 lines, then the macro has to be copied 12times, a little messy and if I have the macro copied more times than the lines, it messes up the last line. Attached are 2 examples of the file, one the start and one showing the final output. Starting file - Format.docm Output format - Format-Completed.docm Basically before I run the macro, I copy the text to line 3 onwards and the list can be between 1-1000 lines (excluding the first 2 header lines), then I place the cursor after the first set of numbers, in this case just after the 3000012 and then run the macro. it then combines some of the text and adjusts the character spaces between the text. Is it possible to write the macro that does the job, but loops/stops when it gets to the last line in the list? Thanks in advance. Barney |
#2
|
||||
|
||||
The following should do the trick, based on your examples
Code:
Sub Macro1() Dim i As Long Dim oRng As Range Dim vPara As Variant For i = 3 To ActiveDocument.Paragraphs.Count Set oRng = ActiveDocument.Paragraphs(i).Range oRng.End = oRng.End - 1 vPara = Split(oRng.Text, vbTab) If UBound(vPara) = 4 Then oRng.Text = vPara(0) & " " & _ vPara(1) & vPara(2) & " " & _ vPara(3) & " " & vPara(4) End If DoEvents Next i 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 |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
VB for Word - Need macro to loop each line in a document | NDeane | Word VBA | 5 | 12-22-2015 08:12 PM |
Loop through Word doc to find and reformat text | Sandy27 | Word VBA | 5 | 01-06-2014 03:48 PM |
Macro to loop in Word | Yamaha Rider | Word VBA | 2 | 02-07-2012 05:33 PM |
WORD Macro - import picture - resize - position - page break - loop | Nano07 | Word VBA | 2 | 11-02-2011 05:14 AM |
Macro for chart formating | QWERTY_Warrior | Excel Programming | 0 | 06-29-2011 07:38 AM |