#1
|
|||
|
|||
Increase Sentence Font at cursor position
Hello,
i wanted to increase the size of the font of the current sentence at the cursor position. So if normal font is 10, the sentence would increase to say 24 and if i moved off that sentence it would adjust back to the normal font size, and the new line at the cursor would increase to 24 font. i have a loop that places each sentence in its own line, but cant figure out how to reference the current line based on the current cursor position to increase the font. this places each sentence on a new line. Code:
Sub Parser() Dim para As Paragraph Dim sents As Sentences Dim sent As Range Set paras = ActiveDocument.Paragraphs For Each para In paras count_Sentences = para.Range.Sentences.Count If count_Sentences > 1 Then Set sents = para.Range.Sentences For Each sent In sents sent.InsertAfter Chr(11) Next End If Next End Sub |
#2
|
||||
|
||||
Please see my response to your separate thread: https://www.msofficeforums.com/word-...line-word.html
Furthermore, Word VBA's notion of what constitutes a sentence isn't what most readers would consider a sentence. For example, consider the following: Mr. Smith spent $1,234.56 at Dr. John's Grocery Store, to buy: 10.25kg of potatoes; 10kg of avocados; and 15.1kg of Mrs. Green's Mt. Pleasant macadamia nuts. For you and me, that would probably count as one sentence; for VBA it counts as 5...
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
For more, and maybe more than you care to know, on Word and sentences, see:
http://gregmaxey.com/word_tip_pages/...sentences.html |
#4
|
|||
|
|||
thanks greg for the link, i frequent your site regularly when i need good info.
I definitely understand what you mean by your example, i think that is an extreme case and for the type of information i am parsing, Using that small script and some other cleaning scripts I can get about 90% accuracy (as far as placing line-breaks between sentence and sentences in there own "lines") which is great for my needs. So i am not worried about parsing sentences right now BUT how to recognize a movement in the cursor position and change the sentence at its current position..automatically. Excel contains a Workbook "change event". If you move from 1 cell to the other, you can have macros run based on that change. I was hoping to accomplish the same thing (i don't see a change event for Word though). as I move my cursor to the next sentence it would change its font size automatically (not the line but the sentence). is there a creative solution, or does a "change" event exist for Word? |
#5
|
|||
|
|||
There is no "Change" event for Word. You may be able to use the "WindowSelectionChange" event.
Option Explicit Private WithEvents mWordApp As Word.Application Private Sub Class_Initialize() Set mWordApp = Word.Application End Sub Private Sub mWordApp_WindowSelectionChange(ByVal oSel As Selection) Beep End Sub |
#6
|
|||
|
|||
thanks Greg,
i placed all 3 in "This Document" (see attachment) is this proper? i ask because I cant get it to run anything.. please let me know if you see something incorrect (i basically changed cursor positions and deleted some words to evoke the change but nothing) |
#7
|
|||
|
|||
Nope it is not proper. Insert an new class module and put that code there. Then initialize the class using something like this in the standard module:
Code:
Option Explicit Private m_selMonitor As Class1 Sub LoadMonitor() Set m_selMonitor = New Class1 End Sub |
#8
|
||||
|
||||
For some useful info on event programming, see:
http://word.mvps.org/FAQs/MacrosVBA/AppClassEvents.htm http://msdn.microsoft.com/en-us/libr.../ff192791.aspx http://msdn.microsoft.com/en-us/libr...ffice.10).aspx
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#9
|
|||
|
|||
thanks greg for the instructions, it works great. and I am going to look into your Sentence Add-On a little more, i am struggling a bit as I test more and more so I think you it will benefit me especially that I can use it within my own subs..
-thanks for the links Paul |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Add multiple rows to Excel 2010 table at cursor position | C J Squibb | Excel Programming | 12 | 11-07-2013 07:35 AM |
Increase font in received messages | Alonso | Outlook | 6 | 02-20-2012 10:04 PM |
Displaying cursor position within cell | MiamiTom | Excel | 0 | 11-18-2011 09:02 AM |
Cursor size varies with font size | r_lewis@fuse.net | Word | 0 | 07-20-2011 06:11 PM |
Retrieve position of Cursor - x & y positions | SDondeti | PowerPoint | 0 | 05-19-2011 11:39 AM |