![]() |
|
#1
|
|||
|
|||
![]()
Greetings. I have been coding VBA and vb.net for 15 years. I have made dozens of time-saving add-ins, applications, and macros in word, excel, access, and powerpoint. I have a question to which I cannot find an answer. I only wish to know "why".
I do not seek an alternative method for doing this (unless it's easy ;-)). I don't have code to show you. I know all about the virtues and vices of style templates. I do not seek to be chastised for wanting to do something so stupid. I only want to know why something does not work. OK - with that as the caveat - If I am in a word document and select modify a style, select the font and change it from Arial to Times New Roman, when I am done with the dialogue all the text of that style changes from Arial to Times New Roman in the document text. If I do the exact same thing in VBA, (find the style from the styles collection and modify the font) the text does not update. I run my code and examine the style in the style manager dialogue box I can see my changes (the font for the style shows Times New Roman), yet the text in the document stubbornly stays Arial. Why? I can force the update by looping through the paragraph collection and applying the style (!) but I don't want to do that. I have searched and searched and cannot find an answer to this question. Maybe one of you knows. |
#2
|
|||
|
|||
![]()
If it's one thing I've learned here it's if your code doesn't work you've done something wrong and it's your fault. You can't share code why? Have a better attitude if you want help.
This works for me: Code:
Sub ModifyStyle() ' ' ' Selection.Find.ClearFormatting Selection.Find.Style = ActiveDocument.Styles("Quote") 'Your Style Here Selection.Find.Replacement.ClearFormatting Selection.Find.Replacement.Font.Size = 14 Selection.Find.Replacement.Font.Bold = True Selection.Find.Replacement.Font.Italic = True With Selection.Find .Text = "?" .Replacement.Text = "^&" .Forward = True .Wrap = wdFindContinue .Format = True .MatchCase = False .MatchWholeWord = False .MatchByte = False .MatchAllWordForms = False .MatchSoundsLike = False .MatchWildcards = True End With Selection.Find.Execute Replace:=wdReplaceAll End Sub |
#3
|
|||
|
|||
![]()
Thanks for the laugh! I needed it today
|
#4
|
||||
|
||||
![]()
Code like:
ActiveDocument.Styles("MyStyle").Font.Italic = True works for me - all content in that Style is immediately updated to have the italic attribute. Of course, if someone has been overriding Style definitions with direct formatting, simply changing the Style definition may not be enough to get the desired result...
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#5
|
||||
|
||||
![]()
I would presume it doesn't work for you because the font name has been locally overridden on your instances of that style. Certainly the following works for me if there is no local font formatting.
Code:
Sub ChangeStyleDef() ActiveDocument.Styles("Normal").Font.Name = "Times New Roman" End Sub ActiveDocument.Range.Font.Reset
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#6
|
|||
|
|||
![]()
Thank you all for the assistance. I am wondering if the characteristics of the document are making this hard. These are engineering manuals that are several 100 pages (between 500-1000) long and have many bespoke styles in them.
I need to do some more research on styles and how they inter-connect. Again, thank you for your assistance and time, and (@Kilroy) I realized you may not have been joking - my apologies if so. I will keep you posted if I make progress. |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
How Do I stop automatic style updates for Word 2013 | Lupe71903 | Word | 2 | 02-27-2018 01:48 PM |
![]() |
markh10178 | Word | 3 | 11-26-2015 04:07 PM |
![]() |
jlumbtx | Office | 1 | 03-13-2015 04:50 PM |
![]() |
Ricyteach | Word VBA | 6 | 03-09-2015 07:11 PM |
Automating document updates with new text | wordfoolish2 | Word | 0 | 01-04-2011 01:01 PM |