Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 02-11-2014, 08:58 AM
ilcaa72 ilcaa72 is offline Increase Sentence Font at cursor position Windows 7 64bit Increase Sentence Font at cursor position Office 2010 64bit
Novice
Increase Sentence Font at cursor position
 
Join Date: Jan 2014
Posts: 27
ilcaa72 is on a distinguished road
Default 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
Reply With Quote
  #2  
Old 02-11-2014, 11:16 PM
macropod's Avatar
macropod macropod is offline Increase Sentence Font at cursor position Windows 7 32bit Increase Sentence Font at cursor position Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
  #3  
Old 02-12-2014, 08:13 AM
gmaxey gmaxey is offline Increase Sentence Font at cursor position Windows 7 32bit Increase Sentence Font at cursor position Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,429
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

For more, and maybe more than you care to know, on Word and sentences, see:
http://gregmaxey.com/word_tip_pages/...sentences.html
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #4  
Old 02-13-2014, 09:37 AM
ilcaa72 ilcaa72 is offline Increase Sentence Font at cursor position Windows 7 64bit Increase Sentence Font at cursor position Office 2010 64bit
Novice
Increase Sentence Font at cursor position
 
Join Date: Jan 2014
Posts: 27
ilcaa72 is on a distinguished road
Default

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?
Reply With Quote
  #5  
Old 02-13-2014, 09:43 AM
gmaxey gmaxey is offline Increase Sentence Font at cursor position Windows 7 32bit Increase Sentence Font at cursor position Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,429
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

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
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #6  
Old 02-13-2014, 10:37 AM
ilcaa72 ilcaa72 is offline Increase Sentence Font at cursor position Windows 7 64bit Increase Sentence Font at cursor position Office 2010 64bit
Novice
Increase Sentence Font at cursor position
 
Join Date: Jan 2014
Posts: 27
ilcaa72 is on a distinguished road
Default

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)
Attached Images
File Type: jpg word change.jpg (177.7 KB, 30 views)
Reply With Quote
  #7  
Old 02-13-2014, 11:04 AM
gmaxey gmaxey is offline Increase Sentence Font at cursor position Windows 7 32bit Increase Sentence Font at cursor position Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,429
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

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
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #8  
Old 02-13-2014, 11:56 AM
macropod's Avatar
macropod macropod is offline Increase Sentence Font at cursor position Windows 7 32bit Increase Sentence Font at cursor position Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
  #9  
Old 02-20-2014, 08:40 AM
ilcaa72 ilcaa72 is offline Increase Sentence Font at cursor position Windows 7 64bit Increase Sentence Font at cursor position Office 2010 64bit
Novice
Increase Sentence Font at cursor position
 
Join Date: Jan 2014
Posts: 27
ilcaa72 is on a distinguished road
Default

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
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Increase Sentence Font at cursor position 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

Other Forums: Access Forums

All times are GMT -7. The time now is 05:53 AM.


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