Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 12-22-2015, 11:09 AM
NDeane NDeane is offline VB for Word - Need macro to loop each line in a document Windows 7 64bit VB for Word - Need macro to loop each line in a document Office 2013
Novice
VB for Word - Need macro to loop each line in a document
 
Join Date: Dec 2015
Posts: 2
NDeane is on a distinguished road
Default VB for Word - Need macro to loop each line in a document

Hi All -

I am VERY new to macros in Word. I have written the following macro for Word that will remove line numbers from the start of each line (1 line per paragraph). These line numbers are automatically created in an EDI software that I pull data from and they need to be removed. The macro is removing everything in the line up to the second word (EDI segment). Instead of changing the counter (value currently set at 80) I would like for the macro to run through the entire document. Some of the EDI files that I pull will have +7000 lines and it will get tiresome to have to change this value each time. The rest of the macro is just removing all of the CR so that the data can be shown as a stream. Trust me, I wish everyone used an EDI viewer because this wouldn't be as much of a pain. Please let me know if you have any thoughts.

' EDI fix Macro
'
Dim i As Long
i = 1
Do Until i > 80
Selection.MoveRight Unit:=wdWord, Count:=2, Extend:=wdExtend
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.MoveDown Unit:=wdLine, Count:=1
i = i + 1
Loop

Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "^p"
.Replacement.Text = ""
.Forward = True
.wrap = wdFindContinue
.Format = False


.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub
Reply With Quote
 

Tags
loop macro, vb, word 2013 lines



Similar Threads
Thread Thread Starter Forum Replies Last Post
VB for Word - Need macro to loop each line in a document macro to add brackets to each line and add single quotes to each word in the line bracketandquotes Word VBA 17 02-16-2015 03:51 PM
Save As Macro using first line of document as document name redzan Word VBA 1 01-31-2015 09:24 PM
VB for Word - Need macro to loop each line in a document Loop through each Line in Word ilcaa72 Word VBA 4 02-13-2014 11:48 AM
VB for Word - Need macro to loop each line in a document Macro to loop in Word Yamaha Rider Word VBA 2 02-07-2012 05:33 PM
VB for Word - Need macro to loop each line in a document WORD Macro - import picture - resize - position - page break - loop Nano07 Word VBA 2 11-02-2011 05:14 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 12:41 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