#1
|
|||
|
|||
Would these macros be possible to make?
Years ago someone here was kind enough to make a macro for me that asked for a word, then sent every instance of that word into a new document so I didn't have to go dig for each sentence/paragraph containing that word manually. It's worked wonders!
But as my workload has increased of late, I was wondering if it's possible to improve it in a certain way. Here's the macro so you can test it yourself and see what I'm talking about (I'm on MS Word 2003, by the way. Old computer but it still works, haha) Code:
Sub GetParas() Dim oDoc As Document Dim oRng As Range Dim strKeyWord As String strKeyWord = InputBox("Enter the word to find") If strKeyWord = "" Then GoTo lbl_Exit Set oRng = ActiveDocument.Range Set oDoc = Documents.Add With oRng.Find Do While .Execute(FindText:=strKeyWord, MatchCase:=False, MatchWholeWord:=True) oDoc.Range.InsertAfter oRng.Paragraphs(1).Range.FormattedText oRng.Paragraphs(1).Range.Delete oRng.Collapse 0 Loop End With oDoc.Range.ParagraphFormat.SpaceBefore = 12 lbl_Exit: Exit Sub Is there a way to set this macro so the spaces in the new document are normal from the get-go? Also, would it be possible to make a macro that takes an entire document and re-arranges the sentences and paragraphs by length? So if you want all your big paragraphs to be at the top and all your shorter paragraphs/single sentences at the bottom, is that sort of thing possible? And if not a macro, is there an online tool that does that sort of thing, sort of like ones that alphabetize things for you? I hope that all made sense, and I'll be happy to clarify if it didn't. Thanks if anyone is able to help :] |
#2
|
|||
|
|||
That is not "normal" for Word even if it is for you. There is a difference between a sentence and a paragraph, especially in Word.
2.2 Why you should press Enter only once to end a paragraph This might do what you want. Code:
Sub GetParas() Dim oDoc As Document Dim oRng As Range Dim strKeyWord As String strKeyWord = InputBox("Enter the word to find") If strKeyWord = "" Then GoTo lbl_Exit Set oRng = ActiveDocument.Range Set oDoc = Documents.Add With oRng.Find Do While .Execute(FindText:=strKeyWord, MatchCase:=False, MatchWholeWord:=True) oDoc.Range.InsertAfter oRng.Paragraphs(1).Range.FormattedText oDoc.Range.InsertParagraphAfter oRng.Paragraphs(1).Range.Delete oRng.Collapse 0 Loop End With oDoc.Range.ParagraphFormat.SpaceBefore = 0 oDoc.Range.ParagraphFormat.SpaceAfter = 0 lbl_Exit: Exit Sub End Sub Nothing wrong with Word 2003. However, I do not have it on my computer so have not tested the macro. I know of no reason why it would not work, though. If you decide to "upgrade" do not get Word 2007. IMO, it was a beta version pushed out by marketing. |
#3
|
|||
|
|||
That did the trick! Thank you so much :]
About the other macro, is that one possible too or is there some online tool for that sort of thing? The convenience of it is just getting the bigger stuff out of the way first by having the biggest-to-smallest order~ Quote:
Last edited by Charles Kenyon; 08-17-2020 at 09:30 AM. Reason: add quote from original post |
#4
|
|||
|
|||
Quote:
It is important to distinguish between paragraph and sentence. They are not synonymous. Which do you want? |
#5
|
|||
|
|||
Quote:
I might use the wrong terms so I'll just describe it like this. Basically let's say you had these three things: A.) A small body of text made of multiple sentences. That takes up about three rows on the screen. And it's up at the top at the moment. B.) A single sentence taking up just one row here in the middle. C.) And a huge body of text. Also made of multiple sentences. Taking up about 15 rows. But let's just use 4 in this example. The macro would take that document and make the new order be C. A. B. so all the big stuff is first and everything lesser is next in line, all the way to single line stuff. And it would keep the vertical spaces in-between the bodies of text, of course :] |
#6
|
||||
|
||||
grumblid
It appears from your examples and the removal of paragraph spacing in the code that your idea on what a paragraph is differs from Word's idea on what it is. It appears you are pressing the Enter key at the end of line and two Enter keys between 'paragraphs'. In Word-speak, a paragraph is defined by that Enter key so a forced line end is actually a new paragraph unless you are using Shift-Enter to go to the next line. I think you will need to post an example document so we can see how you are ending each 'line' of a paragraph. Can you explain the point of a macro to re-arrange your content into physical size order? What sort of content makes this a useful tool? It is easy to sort paragraphs in alphabetical order but arranging chunks of text by the number of characters doesn't seem to be useful in any way other than as an academic exercise.
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#7
|
|||
|
|||
Quote:
I have a large number of creative projects that prioritize the most developed entries (big walls of text) at the top and then I work my way down to the lesser ones (smaller walls then eventually single sentences). So it's both faster and easier to have everything big and interesting up top and everything else get smaller and smaller as I go down. I work with thousands of pages and everything eventually becomes a mess of entries of all sizes. So a way to instantly organize bodies of text like that would be a godsend~ |
#8
|
||||
|
||||
OK, the coding of a macro to do what you ask is possible but unlikely to actually satisfy you. All macros must be based on assumptions and it appears that the assumptions we would need to make are likely to be incorrect enough times that the result would be pointless.
If you had a VERY regular delimiting factor that lets us say this is the end of the project chunk then we could use that but you must never vary from that 'separator' or inadvertently include that separator in the middle of a project. Based on your input information so far, I'm going to assume that your 'project' groups are delimited by empty paragraphs. If that is the case, I would start by moving each of these projects into table cells which would create a regular structure where the macro could now look at your content delimited by something more tangible and controllable. It would then be a far simpler task to add a column with a character count and sort the table based on that column.
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#9
|
|||
|
|||
Quote:
Thanks for the suggestion, but personally table cells would be a nightmare for what I have. Though 'character count' does kind of sound like the general term I'm thinking of. Like if a macro or online tool could look at a document like 'okay this body of text has 200 characters and this one has 300, so the one with 300 goes above that one.' But of course do that for the entire document all at once. Outside of MS Word Macros, does anyone have any suggestions for an online tool that might be able to do that? I've used sites that alphabetize words, add up multiple numbers that you copy/paste onto it, and stuff like that. But not one like this yet :{o |
#10
|
||||
|
||||
Without seeing a sample doc, we really have no idea what would actually work. If you provide a sample document which shows what you are looking at, someone here can have a go at providing code that would do the job.
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#11
|
|||
|
|||
Here ya go, I made an example version just to show you what I mean. I work with tons of documents with hundreds of pages each, but this is shows a basic idea what I see most of the time in terms of the variety of character counts in bodies of text.
https://i.ibb.co/TKzRfY7/Example1.png And here's what the hypothetical macro would do to that document in an instant. https://i.ibb.co/ZHK06X4/Example2.png It makes me smile just imagining it, haha~ To think all the time I could save :] |
#12
|
|||
|
|||
If it is a lengthy document, it would not be in an instant. Perhaps overnight.
|
#13
|
|||
|
|||
Really? What would cause it to take so long? :{o
|
#14
|
||||
|
||||
I can't see the images you posted as my corporate network blocks that site.
If you haven't shown the hidden formatting characters (spaces, tabs, paragraph marks) in your screen shot then you still haven't given enough information for people to work with.
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#15
|
|||
|
|||
Quote:
Did that help describe the kind of macro function I'm going for? Like I said I don't know the technical side of it, only the idea :{o |
Tags |
help me, macros, ms word |
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
How to automatically enable the macros upon opening a file with macros? | laurieli | Office | 7 | 01-17-2016 08:56 AM |
Can you make templates dynamically update macros/etc. from Normal.DOT? | New Daddy | Word | 2 | 11-18-2013 09:07 AM |
VBA macros | tays01s | Word VBA | 6 | 08-03-2011 09:42 PM |
Macros | nore | Outlook | 0 | 06-01-2011 04:39 PM |
Macros | Desertwrangler | Word VBA | 6 | 06-25-2010 07:06 AM |