更改字体样式和大小并反转更改 [英] Change font style and size and reverse the changes

查看:67
本文介绍了更改字体样式和大小并反转更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello Support,


我想使用一个宏将字体样式更改为Times New Roman,将活动文档的字体大小更改为25(整个文档) 。
  然后我想使用其他宏来反转更改。 
我使用了"Sub SetFontStyleAndSize"中的代码。更改/设置字体样式Times New Roman 25,这似乎工作正常。 
我使用了"Sub RemoveFontStyleAndSize"中的代码。   以反转我使用"Sub SetFontStyleAndSize"所做的操作。
  然而,我们遇到的问题是Sub"RemoveFontStyleAndSize"中的代码。删除所有直接格式,包括在运行宏之前应用的直接格式。我们只希望代码反转我应用的
的更改。   现在我想弄清楚实现这一目标的最佳方法是什么。以下是我正在使用的潜艇。


****谢谢你,我很感谢你的帮助。


Sub SetFontStyleAndSize()


'更改整个文档中的字体样式并增加字体大小


'http://word.mvps.org/faqs/customization/ReplaceAnywhere.htm


Dim rngStory  
As Word.Range


Dim lngJunk   
As Long


   
'修复由Peter Hewett提供的跳过的空白页眉/页脚问题


   
lngJunk = ActiveDocument.Sections(1).Headers(1).Range.StoryType


<跨度>&NBSP;&NBSP;&NBSP;
'迭代当前文档中的所有故事类型


   ;&NBSP;
For each rngStory在ActiveDocument.StoryRanges


    &NBSP;&NBSP;
'迭代所有关联的故事


     ;&NBSP;
执行


     
使用rngStory.Font


      ;&NBSP;&NBSP;
.Name =" Times New Roman"


   &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;
.Size = 25


       ;&NBSP;&NBSP;
结束


       ;&NBSP;
'获取下一个链接的故事(如果有的话)


   &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;
设置rngStory = rngStory.NextStoryRange


     ;&NBSP;
循环直到rngStory没什么


  下一步


End Sub


 


 


 






Sub RemoveFontStyleAndSize


'更改整个文档中的字体样式并增加字体大小


'http:// word.mvps.org/faqs/customization/ReplaceAnywhere.htm


Dim rngStory  
As Word.Range


Dim lngJunk   
As Long


   
'修复由Peter Hewett提供的跳过的空白页眉/页脚问题


&NBSP;&NBSP;&NBSP;
lngJunk = ActiveDocument.Sections(1).Headers(1).Range.StoryType


<跨度>&NBSP;&NBSP;&NBSP;
'迭代当前文档中的所有故事类型


   ;&NBSP;
For each rngStory在ActiveDocument.StoryRanges


    &NBSP;&NBSP;
'迭代所有关联的故事


     ;&NBSP;
执行


     
使用rngStory.Font


。Rest


       
结束


       ;&NBSP;
'获取下一个链接的故事(如果有的话)


   &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;
设置rngStory = rngStory.NextStoryRange


     ;&NBSP;
循环直到rngStory没什么


  下一步


End Sub

解决方案

这样做的唯一可靠方法是:

1.启用"跟踪变更"在进行字体更改之前,稍后拒绝该更改,以便所有字体都返回到其原始状态;或
$
2.进行更改,然后使用"撤消"稍后撤消更改;或

3.进行更改,然后关闭文档而不保存以后。


只有第一个选项提供了一种保留字体更改后编辑的方法。


当然,如果您的文档的创建者通过样式应用了所有格式,那么您就不会遇到"删除所有直接格式化"类型的问题。


Hello Support,

I want to use one macro to change the font style to Times New Roman and the font size to 25 for the active document (the entire document).  Then I want to utilize a different macro to reverse the changes.  I used the code in "Sub SetFontStyleAndSize" to change/set the font style Times New Roman 25, which seems to work fine.  I used the code in "Sub RemoveFontStyleAndSize"  to reverse what I did with "Sub SetFontStyleAndSize".  However, the problem we have encountered is that the code in Sub "RemoveFontStyleAndSize" removes all direct formatting including direct formatting applied before the macro was run. We only want the code to reverse the changes that I applied.  Now I am trying to figure out what's the best way to accomplish this. The following are the subs I am using.

****Thank you and I appreciate the help.

Sub SetFontStyleAndSize()

'Change font style and increase font size in entire document

' http://word.mvps.org/faqs/customization/ReplaceAnywhere.htm

Dim rngStory  As Word.Range

Dim lngJunk   As Long

    'Fix the skipped blank Header/Footer problem as provided by Peter Hewett

    lngJunk = ActiveDocument.Sections(1).Headers(1).Range.StoryType

    'Iterate through all story types in the current document

    For Each rngStory In ActiveDocument.StoryRanges

      'Iterate through all linked stories

      Do

      With rngStory.Font

        .Name = "Times New Roman"

        .Size = 25

        End With

        'Get next linked story (if any)

        Set rngStory = rngStory.NextStoryRange

      Loop Until rngStory Is Nothing

  Next

End Sub

 

 

 

Sub RemoveFontStyleAndSize

'Change font style and increase font size in entire document

' http://word.mvps.org/faqs/customization/ReplaceAnywhere.htm

Dim rngStory  As Word.Range

Dim lngJunk   As Long

    'Fix the skipped blank Header/Footer problem as provided by Peter Hewett

    lngJunk = ActiveDocument.Sections(1).Headers(1).Range.StoryType

    'Iterate through all story types in the current document

    For Each rngStory In ActiveDocument.StoryRanges

      'Iterate through all linked stories

      Do

      With rngStory.Font

.Rest

        End With

        'Get next linked story (if any)

        Set rngStory = rngStory.NextStoryRange

      Loop Until rngStory Is Nothing

  Next

End Sub

解决方案

The only reliable ways of doing this would be to:
1. Turn on 'Track Changes' before making the font change, then reject that change later on, so all the fonts are returned to their original state; or
2. Make the changes, then use Undo to undo them later on; or
3. Make the changes, then close the document without saving later on.

Only the first option provides a means of retaining edits made after the font change.

Of course, if the creator of your document applied all formatting via Styles, you wouldn't have problems of the 'removes all direct formatting' kind.


这篇关于更改字体样式和大小并反转更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆