Macro to increase Font of selected text

uncle
3StarLounger
Posts: 278
Joined: 04 Aug 2010, 19:50

Macro to increase Font of selected text

Post by uncle »

Am trying to create a macro that when I select text, it increases it to 14 (Times New Roman). Trying but failing

I know to use the keyboard to select the text. I then go to Font window to increase size to 14, then I exit the macro and --nothing.

Thank you

User avatar
HansV
Administrator
Posts: 78457
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Macro to increase Font of selected text

Post by HansV »

How about

Code: Select all

Sub FontSize14()
    On Error GoTo ErrHandler
    Selection.Font.Size = 14
    Exit Sub
ErrHandler:
    MsgBox "Cannot set font size of this selection!", vbExclamation
End Sub
Best wishes,
Hans

uncle
3StarLounger
Posts: 278
Joined: 04 Aug 2010, 19:50

Re: Macro to increase Font of selected text

Post by uncle »

Thank you

User avatar
Charles Kenyon
5StarLounger
Posts: 615
Joined: 10 Jan 2016, 15:56
Location: Madison, Wisconsin

Re: Macro to increase Font of selected text

Post by Charles Kenyon »

A different method would be to create a character style that has TNR 14 pt and apply that rather than direct formatting through a macro.
You can attach a keyboard shortcut to that style. Doing this makes for less complex document files.
https://answers.microsoft.com/en-us/mso ... 5883735330

User avatar
ChrisGreaves
PlutoniumLounger
Posts: 15610
Joined: 24 Jan 2010, 23:23
Location: brings.slot.perky

Re: Macro to increase Font of selected text

Post by ChrisGreaves »

Charles Kenyon wrote:
13 Jul 2022, 15:06
A different method ...
I agree, except I would have started "A better method .." where by better I mean less time spent further down the road.:cool:
Cheers, Chris
There's nothing heavier than an empty water bottle

uncle
3StarLounger
Posts: 278
Joined: 04 Aug 2010, 19:50

Re: Macro to increase Font of selected text

Post by uncle »

Thank you Chris, Charles, but Hans' methods works fine for me, and it is what I am accustomed to.

User avatar
Charles Kenyon
5StarLounger
Posts: 615
Joined: 10 Jan 2016, 15:56
Location: Madison, Wisconsin

Re: Macro to increase Font of selected text

Post by Charles Kenyon »

Uncle,
If you are regularly using Word you NEED to learn to use styles. Every minute you spend using Word without using styles is a half hour you'll spend down the road trying to fix something.
https://www.addbalance.com/usersguide/s ... m#Overview

User avatar
ChrisGreaves
PlutoniumLounger
Posts: 15610
Joined: 24 Jan 2010, 23:23
Location: brings.slot.perky

Re: Macro to increase Font of selected text

Post by ChrisGreaves »

Charles Kenyon wrote:
14 Jul 2022, 18:45
Every minute you spend using Word without using styles is a half hour you'll spend down the road trying to fix something.
Charles, I disagree. :grin:
I spent many years converting old documents of my clients to MSWord and cleaning them up on the way.
That is the basis of my DoCle[an] application
"Every minute you spend using Word without using styles is a several hours you'll spend down the road trying to fix something".

Uncle. I promise you: Start using Styles in MSWord, MSExcel and so on. You WILL be glad that you did.
Let me know here if you would like me to supply some simple but good examples.

Cheers, Chris
There's nothing heavier than an empty water bottle

User avatar
Charles Kenyon
5StarLounger
Posts: 615
Joined: 10 Jan 2016, 15:56
Location: Madison, Wisconsin

Re: Macro to increase Font of selected text

Post by Charles Kenyon »

:clapping: I agree but was afraid of being dismissed as too pro-styles.

User avatar
ChrisGreaves
PlutoniumLounger
Posts: 15610
Joined: 24 Jan 2010, 23:23
Location: brings.slot.perky

Re: Macro to increase Font of selected text

Post by ChrisGreaves »

Charles Kenyon wrote:
21 Jul 2022, 16:58
:clapping: I agree but was afraid of being dismissed as too pro-styles.
Charles, you are a bright young lad :grin: ; Tell me, how on earth can one be TOO pro-styles?
I used to demonstrate in class how styles, properly set up, can basically create a document by judicious use of "Style for following paragraph".

Then I wrote an application that worked out an appropriate level (1 through 9) for every paragraph in a document, worked out where the transition of levels suggested a Heading-n paragraph, worked out appropriate text for that paragraph, and hence generated a Heading-n paragraph of text, so that a TOC could be generated automatically from an un-styled document.

Mind you, some folks think that I'm a bit obsessive when it comes to The Power Of Styles

Cheers, Chris
There's nothing heavier than an empty water bottle

uncle
3StarLounger
Posts: 278
Joined: 04 Aug 2010, 19:50

Re: Macro to increase Font of selected text

Post by uncle »

Chris -Thank you for your kind offer but I am happy w/o styles. I do not use Word for reports or other business reasons so I don't have long documents and have the need for different styles.

User avatar
Charles Kenyon
5StarLounger
Posts: 615
Joined: 10 Jan 2016, 15:56
Location: Madison, Wisconsin

Re: Macro to increase Font of selected text

Post by Charles Kenyon »

@uncle,

You get to make your choices; you are an adult.

Please take a moment to read what I wrote here: https://www.addbalance.com/usersguide/s ... m#Overview
In part, I wrote long ago:
Trying to use Word without understanding and using styles is like pushing on a string. I resisted learning and using styles for years and now regret every day of those years because although that string was still very hard to push, it kept getting longer and longer, and had some very important projects tied to it! Once you understand styles and the Word concept of organizing things into Chinese boxes everything falls into place and instead of pushing a string, you can push a button that turns on the very powerful text processing machine known as Microsoft Word and it will start doing your work for you instead of running around behind you trying to undo what you thought you just did.
:flee:
The link provides more information and quotes.

User avatar
BobH
UraniumLounger
Posts: 9278
Joined: 13 Feb 2010, 01:27
Location: Deep in the Heart of Texas

Re: Macro to increase Font of selected text

Post by BobH »

OK, you style-ish mavens, where does one learn about using styles?

Sorry, Charles! I missed your link. I can see spending a good deal of time there.
Bob's yer Uncle
(1/2)(1+√5)
Dell Intel Core i5 Laptop, 3570K,1.60 GHz, 8 GB RAM, Windows 11 64-bit, LibreOffice,and other bits and bobs

User avatar
Charles Kenyon
5StarLounger
Posts: 615
Joined: 10 Jan 2016, 15:56
Location: Madison, Wisconsin

Re: Macro to increase Font of selected text

Post by Charles Kenyon »