Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 01-31-2018, 02:09 PM
beardsa beardsa is offline Loop macro to adjust text formating within Word Windows 10 Loop macro to adjust text formating within Word Office 2016
Novice
Loop macro to adjust text formating within Word
 
Join Date: Jan 2018
Posts: 1
beardsa is on a distinguished road
Default 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
Attached Files
File Type: docm Format.docm (18.3 KB, 13 views)
File Type: docm Format-completed.docm (19.5 KB, 13 views)
Reply With Quote
  #2  
Old 02-01-2018, 12:10 AM
gmayor's Avatar
gmayor gmayor is offline Loop macro to adjust text formating within Word Windows 10 Loop macro to adjust text formating within Word Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,104
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 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
Reply With Quote
Reply



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 macro to adjust text formating within Word Loop through Word doc to find and reformat text Sandy27 Word VBA 5 01-06-2014 03:48 PM
Loop macro to adjust text formating within Word Macro to loop in Word Yamaha Rider Word VBA 2 02-07-2012 05:33 PM
Loop macro to adjust text formating within Word 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

Other Forums: Access Forums

All times are GMT -7. The time now is 03:57 AM.


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