 | Member with 62 posts. | | | | Word Macro: loop until end of file? hello,
how do i loop an instruction until the end of the document ?
i wasn't able to find the right way using google :\
please help
Last edited by kejo : 01-May-2009 02:08 PM.
| | Distinguished Member with 3,728 posts. | | Join Date: Sep 2003 Location: Atlanta, GA - Planet Earth Experience: Brilliant When Sober | | Explain in detail what the macro is going to be doing.
Regards,
Rollin | | Member with 62 posts. | | | | it's going to find a string and replace.
my macro will do it once.
i want it to find and replace all the strings in my file (until the end of file) | | Distinguished Member with 3,728 posts. | | Join Date: Sep 2003 Location: Atlanta, GA - Planet Earth Experience: Brilliant When Sober | | Why not use the wdReplaceAll method?? Code: Sub ReplaceAll()
With ActiveDocument.Content.Find
.ClearFormatting
.Replacement.ClearFormatting
.Execute findtext:="SearchText", replaceWith:="ReplaceText", Replace:=wdReplaceAll
End With
End Sub
| | Member with 62 posts. | | | | thank you Rollin_Again, but i need to learn how to loop untill End of File.
can you please tell me how to do this? | | Distinguished Member with 3,728 posts. | | Join Date: Sep 2003 Location: Atlanta, GA - Planet Earth Experience: Brilliant When Sober | | You still need to explain exactly why and how you want to loop through the document. Do you want to loop through line by line and look for a certain phrase or word. Do you want to loop through word by word? You can try the code below. It looks for the built in bookmark called "EndOfDoc" Code:
Sub LoopDoc()
Selection.HomeKey Unit:=wdStory
Selection.HomeKey Unit:=wdLine
i = 1
Do Until ActiveDocument.Bookmarks("\Sel").Range.End = _
ActiveDocument.Bookmarks("\EndOfDoc").Range.End
MsgBox ("You are on line " & i)
Selection.MoveDown
i = i + 1
Loop
MsgBox ("You have reached the end of the document")
End Sub
Regards,
Rollin
Last edited by Rollin_Again : 01-May-2009 12:58 PM.
| | Member with 62 posts. | | | | ok thank you very much Rollin_Again, what i want to do is:
find every underlined string in the doc and make the first char of the found string red | | Member with 62 posts. | | | | Quote:
Originally Posted by Rollin_Again You still need to explain exactly why and how you want to loop through the document. Do you want to loop through line by line and look for a certain phrase or word. Do you want to loop through word by word? You can try the code below. It looks for the built in bookmark called "EndOfDoc" Code:
Sub LoopDoc()
Selection.HomeKey Unit:=wdStory
Selection.HomeKey Unit:=wdLine
i = 1
Do Until ActiveDocument.Bookmarks("\Sel").Range.End = _
ActiveDocument.Bookmarks("\EndOfDoc").Range.End
MsgBox ("You are on line " & i)
Selection.MoveDown
i = i + 1
Loop
MsgBox ("You have reached the end of the document")
End Sub
Regards,
Rollin | i am sorry to tell you that your code generates an infinite loop | | Distinguished Member with 3,728 posts. | | Join Date: Sep 2003 Location: Atlanta, GA - Planet Earth Experience: Brilliant When Sober | | I modified the original code that I posted. Are you using the updated code as it appears in the post above or are you using the original code?
Regards,
Rollin | | Distinguished Member with 3,728 posts. | | Join Date: Sep 2003 Location: Atlanta, GA - Planet Earth Experience: Brilliant When Sober |
01-May-2009, 04:01 PM
#10 | Try this Code: Sub ChangeColor()
For Each vWord In ActiveDocument.Words
If vWord.Underline = 1 Then
vWord.Select
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend
Selection.Font.Color = wdColorRed
End If
Next
End Sub
Regards,
Rollin | | Member with 62 posts. | | |
02-May-2009, 01:36 PM
#11 | ok your code works fine, but i need to find lines instead of words.
how to do it?
i need something like this (don't know if it exists): Code: For Each vLine In ActiveDocument.Lines
| | Distinguished Member with 3,728 posts. | | Join Date: Sep 2003 Location: Atlanta, GA - Planet Earth Experience: Brilliant When Sober |
02-May-2009, 02:13 PM
#12 | I'm still a bit unclear on what you are trying to accomplish. Can you please provide more explanation on why you want to search line by line? Will the underlined strings you are searching for consist of more than one word?
Regards,
Rollin | | Member with 62 posts. | | |
02-May-2009, 04:20 PM
#13 | I have many numbered lists like this one: Code: 1. first item
2. second item
3. third item
and want to make red the number of the underlined line, like this: Code: 1. first item
2. second item
3. third item
how can i do this?
i have tried some solutions but none worked.
hope you guys are able to help me.
thanks in advance.
Last edited by kejo : 03-May-2009 08:49 AM.
| | Member with 62 posts. | | |
03-May-2009, 05:07 AM
#14 | | | | Distinguished Member with 3,728 posts. | | Join Date: Sep 2003 Location: Atlanta, GA - Planet Earth Experience: Brilliant When Sober |
03-May-2009, 08:49 AM
#15 | Can you post a sample document?
Regards,
Rollin |  THIS THREAD HAS EXPIRED.
Are you having the same problem?
We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.
|
Smart Search
| Find your solution! | |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | | |  WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who want to help you solve your computer problems. See our Welcome Guide to get started.
| You Are Using: |
Advertisements do not imply our endorsement of that product or service.
All times are GMT -5. The time now is 01:09 AM.
Copyright © 1996 - 2009 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd. | |
|