Paul,
I tried the macro and it works when there is a pattern match. When there is no pattern match, it seems to get stuck in the while loop. I suppose one could add a counter in the loop and exit it after a certain number of attempts. Do you know of an easier way to abort the process when there...
Thanks, MakeItSo. I worked on my own code (before seeing yours) and came up with this:
Sub KillContent()
Dim StartRan As Long, EndRan As Long, TargetStr As String
TargetStr = InputBox("Text to find", "Content Killer")
StartRan = Selection.End
With Selection.Find
.Forward = True...
thanks for the code tips. I'll work on it. As for my example, I'll try again:
Original text: Systems Thinking provides a disciplined way
Cursor location: beginning of line
String I entered: di
What should be deleted: "Systems Thinking provides a"
Desired result: way
What is deleted: "Systems...
Paul,
thanks for the suggestion. It works, but it finds only a character, not a pattern.
Original text: Systems Thinking provides a disciplined way
String I entered: di
Cursor location: beginning of text
Desired result: Systems Thinking provides a way
Actual result: inking provides a way...
Skip,
I thought I included an example of text in my original query. In any case. here's another example.
Original sentence: A boy walks down the road and falls.
Cursor location: At the highlight, just after "boy"
Search string: fa
Text to be deleted: walks down the road and
Final sentence: A...
Sorry if my request seemed presumptuous. This is what I have so far.
Sub DeleteNWords()
Dim WordsToDelete As String
WordsToDelete = InputBox("How many words to cut?")
Selection.MoveRight Unit:=wdWord, Count:=Val(WordsToDelete), Extend:=wdExtend
Selection.Cut
End Sub
So the key is...
Hi,
I'm looking for a macro that will delete (or cut/copy) text from the cursor location to the nearest match of a pattern that the macro requests. For example, if the cursor is just after the "r" in "for" in the previous sentence, and I entered "cu" as the pattern, the macro should change...
Paul,
Thanks for the suggestions. I rebooted computer (error still appeared) and repaired Office (error still appeared). I have a similar function that inserts heading references, and that works fine. I once again created a macro by recording the keystrokes that insert a figure cross reference...
Thanks for your post.
In my original post, I stated that this is a recorded macro, that is, I used Word to record this macro while I inserted a reference to a figure. When I recorded this macro, Word did indeed insert a reference to a figure. I do not think the code is the problem.
Rather...
Paul,
Thanks for the tip. There is indeed a Figure 1 caption in the document. I recorded the macro as I was creating the cross reference to Figure 1. When I then tried to run the macro, I received the error. Do you have any other ideas?
Bruce
Hi,
I recorded this macro in Word 2010 (intending to later modify it). Note, when I recorded the macro, Word inserted a figure reference, which is what I wanted it to do.
Sub Macro3()
Selection.InsertCrossReference ReferenceType:="Figure", ReferenceKind:= _
wdOnlyLabelAndNumber...
Paul,
Could you possibly/please spend a few minutes adding some comments to the code? I think I'd learn a lot by understanding it better, and some comments along the way would help. I ran it on a short sentence, hoping that I'd understand it. I do, sort of. But some comments would, I'm sure...
This is fantastic! Thanks so much. I just ran it on a manuscript and immediately got some insight into word usage, as in, "wow, did I really use that word 53 times?"
Thanks again,
Bruce
Hi,
Does anyone have code for counting the number of occurrences of each word in an MS Word document?
Example: the code run on a very short document containing only "the boy ran to the home"
would produce
the 2
boy 1
ran 1
etc.
thanks, Bruce
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.