PDA

View Full Version : [SOLVED:] Focus Mode



Programmer_n
10-23-2016, 03:57 AM
Recently, I came across some app with focus mode. It changes the current paragraph where the cursor is to dark font and lightens the font color of other paragraphs. So, the attention stays in that particular paragraph, which is visually arresting.

Is it possible to create such focus mode in word?

My work till now is to create a style with dark font and another with light font and call the light font style to all paragraphs but dark one to current paragraph. It is clumsy approach, I reckon.

This link below gives an option to select a sentence adding color to the selection is easy. The question is about paragraph.

http://www.vbaexpress.com/forum/showthread.php?39058-Select-a-Sentence/page2

gmaxey
10-23-2016, 06:44 AM
Perhaps something like this:


'This in a stardard module:
Option Explicit
Dim oAppClass As New clsApp
Public Sub AutoExec()
Set oAppClass.oApp = Word.Application
End Sub
Sub AutoNew()
Set oAppClass.oApp = Word.Application
End Sub
Sub AutoOpen()
Set oAppClass.oApp = Word.Application
ActiveDocument.Range(0, 0).Select
End Sub
'This in a class moduled named clsAPP
Option Explicit
Public WithEvents oApp As Word.Application
Private Sub oApp_WindowSelectionChange(ByVal Sel As Selection)
ActiveDocument.Styles("Normal").Font.ColorIndex = wdGray50
ActiveDocument.Styles("Focus").Font.ColorIndex = wdBlack
ActiveDocument.Range.Style = "Normal"
Selection.Paragraphs(1).Style = "Focus"
lbl_Exit:
Exit Sub
End Sub

gmaxey
10-23-2016, 07:19 AM
I think I like this better:


Private Sub oApp_WindowSelectionChange(ByVal Sel As Selection)
'ActiveDocument.Styles("Normal").Font.ColorIndex = wdGray50
ActiveDocument.Range.Font.Reset
Selection.Paragraphs(1).Range.Font.ColorIndex = wdBlack
lbl_Exit:
Exit Sub
End Sub



As long as all of your text is initially formatted using a style and the base font color is not "Auto" or "Black" then you should be able to create an effective contrast.

Programmer_n
10-23-2016, 08:24 PM
Thanks the code below works.


Sub test()
ActiveDocument.Styles("Normal").Font.ColorIndex = wdGray25
ActiveDocument.Range.Font.Reset
Selection.Paragraphs(1).Range.Font.ColorIndex = wdBlack
lbl_Exit:
Exit Sub
End Sub

What does this means?
Sub oApp_WindowSelectionChange(ByVal Sel As Selection)

gmaxey
10-23-2016, 08:36 PM
It is a event that fires when you change the selection from one point to another

Programmer_n
10-23-2016, 08:50 PM
It is a event that fires when you change the selection from one point to another

Thanks


Sub Paragraph_focus()
ActiveDocument.Styles("Normal").Font.ColorIndex = wdGray25
ActiveDocument.Range.Font.Reset
Selection.Paragraphs(1).Range.Font.ColorIndex = wdBlack
lbl_Exit:
Exit Sub
End Sub
Sub Sentence_focus()
ActiveDocument.Styles("Normal").Font.ColorIndex = wdGray25
ActiveDocument.Range.Font.Reset
With Selection.Sentences(1)
.Bold = True
.Font.ColorIndex = wdBlack
End With
End Sub


Slightly amended your approach to make it work for sentence level. Even for the code above, when I put cursor pointer within the sentence and run the code, it works.