Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 08-17-2020, 08:36 AM
grumblid grumblid is offline Would these macros be possible to make? Windows 7 64bit Would these macros be possible to make? Office 2003
Novice
Would these macros be possible to make?
 
Join Date: Jul 2016
Posts: 23
grumblid is on a distinguished road
Default 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
You'll notice when you use it, the vertical spaces between each of the sentences/paragraphs in the new document aren't clickable. Meaning if you want to have them work normally you have to Clear Formatting, which makes them all clump together, and then you have to go create normal spaces manually by pressing Enter at the start of each sentence/paragraph.



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 :]
Reply With Quote
  #2  
Old 08-17-2020, 09:11 AM
Charles Kenyon Charles Kenyon is offline Would these macros be possible to make? Windows 10 Would these macros be possible to make? Office 2019
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,083
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

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.
Reply With Quote
  #3  
Old 08-17-2020, 09:19 AM
grumblid grumblid is offline Would these macros be possible to make? Windows 7 64bit Would these macros be possible to make? Office 2003
Novice
Would these macros be possible to make?
 
Join Date: Jul 2016
Posts: 23
grumblid is on a distinguished road
Default

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:
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?

Last edited by Charles Kenyon; 08-17-2020 at 09:30 AM. Reason: add quote from original post
Reply With Quote
  #4  
Old 08-17-2020, 09:32 AM
Charles Kenyon Charles Kenyon is offline Would these macros be possible to make? Windows 10 Would these macros be possible to make? Office 2019
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,083
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

Quote:
Originally Posted by grumblid View Post
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~
That one is beyond the time I have available right now but someone else likely will do it for you. If not, I may try in a day or so as a learning experience if no one does.

It is important to distinguish between paragraph and sentence. They are not synonymous. Which do you want?
Reply With Quote
  #5  
Old 08-17-2020, 09:46 AM
grumblid grumblid is offline Would these macros be possible to make? Windows 7 64bit Would these macros be possible to make? Office 2003
Novice
Would these macros be possible to make?
 
Join Date: Jul 2016
Posts: 23
grumblid is on a distinguished road
Default

Quote:
Originally Posted by Charles Kenyon View Post
That one is beyond the time I have available right now but someone else likely will do it for you. If not, I may try in a day or so as a learning experience if no one does.

It is important to distinguish between paragraph and sentence. They are not synonymous. Which do you want?
Well hey, I'm grateful either way :]

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 :]
Reply With Quote
  #6  
Old 08-17-2020, 03:43 PM
Guessed's Avatar
Guessed Guessed is offline Would these macros be possible to make? Windows 10 Would these macros be possible to make? Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

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
Reply With Quote
  #7  
Old 08-17-2020, 06:54 PM
grumblid grumblid is offline Would these macros be possible to make? Windows 7 64bit Would these macros be possible to make? Office 2003
Novice
Would these macros be possible to make?
 
Join Date: Jul 2016
Posts: 23
grumblid is on a distinguished road
Default

Quote:
Originally Posted by Guessed View Post
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.
I don't know any of the technical stuff with MS Word, so yeah if I'm misusing terms that's why. I figured I'd just describe the kind of macros I'm going for and see what the experts say about it :]

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~
Reply With Quote
  #8  
Old 08-17-2020, 09:37 PM
Guessed's Avatar
Guessed Guessed is offline Would these macros be possible to make? Windows 10 Would these macros be possible to make? Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

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
Reply With Quote
  #9  
Old 08-18-2020, 05:25 AM
grumblid grumblid is offline Would these macros be possible to make? Windows 7 64bit Would these macros be possible to make? Office 2003
Novice
Would these macros be possible to make?
 
Join Date: Jul 2016
Posts: 23
grumblid is on a distinguished road
Default

Quote:
Originally Posted by Guessed View Post
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.
I mean if it works, I'm pretty easy to satisfy :]

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
Reply With Quote
  #10  
Old 08-18-2020, 06:17 AM
Guessed's Avatar
Guessed Guessed is offline Would these macros be possible to make? Windows 10 Would these macros be possible to make? Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

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
Reply With Quote
  #11  
Old 08-18-2020, 08:00 AM
grumblid grumblid is offline Would these macros be possible to make? Windows 7 64bit Would these macros be possible to make? Office 2003
Novice
Would these macros be possible to make?
 
Join Date: Jul 2016
Posts: 23
grumblid is on a distinguished road
Default

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 :]
Reply With Quote
  #12  
Old 08-18-2020, 12:20 PM
Charles Kenyon Charles Kenyon is offline Would these macros be possible to make? Windows 10 Would these macros be possible to make? Office 2019
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,083
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

If it is a lengthy document, it would not be in an instant. Perhaps overnight.
Reply With Quote
  #13  
Old 08-18-2020, 01:27 PM
grumblid grumblid is offline Would these macros be possible to make? Windows 7 64bit Would these macros be possible to make? Office 2003
Novice
Would these macros be possible to make?
 
Join Date: Jul 2016
Posts: 23
grumblid is on a distinguished road
Default

Quote:
Originally Posted by Charles Kenyon View Post
If it is a lengthy document, it would not be in an instant. Perhaps overnight.
Really? What would cause it to take so long? :{o
Reply With Quote
  #14  
Old 08-18-2020, 03:39 PM
Guessed's Avatar
Guessed Guessed is offline Would these macros be possible to make? Windows 10 Would these macros be possible to make? Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

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
Reply With Quote
  #15  
Old 08-18-2020, 03:57 PM
grumblid grumblid is offline Would these macros be possible to make? Windows 7 64bit Would these macros be possible to make? Office 2003
Novice
Would these macros be possible to make?
 
Join Date: Jul 2016
Posts: 23
grumblid is on a distinguished road
Default

Quote:
Originally Posted by Guessed View Post
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.
I wasn't sure how to have a spoiler or hide image button (so it doesn't stretch the page) so I went with a link, but I'll just attach the files for you. Hopefully you can see them~

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
Attached Images
File Type: png Example1.png (40.5 KB, 19 views)
File Type: png Example2.png (40.8 KB, 20 views)
Reply With Quote
Reply

Tags
help me, macros, ms word

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Would these macros be possible to make? 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
Would these macros be possible to make? VBA macros tays01s Word VBA 6 08-03-2011 09:42 PM
Macros nore Outlook 0 06-01-2011 04:39 PM
Would these macros be possible to make? Macros Desertwrangler Word VBA 6 06-25-2010 07:06 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 04:48 PM.


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