计算机兴趣——Word——宏——一键处理百度百科文字格式整理

本文提供了一款Word宏代码,能够一键快速格式化从网页复制的内容,特别针对百度百科等网站,实现标题、字体大小及颜色等自动化调整。
    计算机是用来自动化人工作的。。。
    
    这篇文章是干什么的?当你复制网上的文字,再粘贴到word上时,往往需要修改格式。eg:字体大小,居中,换行,设置标题。这种重复枯燥的操作,就应当交由计算机一键化秒秒钟处理,将人解放出来。所以,这有了这篇文章。
    
    你需要安装Office Word 2007,如果是Word 2003,可能,会出一点点小问题,删除出问题的那段代码就行了。因为有些东西Word 2007的东西,Word 2003不支持。如果是WPS的话,很抱歉,人家几百M的软件的功能还是强大很多的。(WPS免费版没有 宏 的功能)。

    原理:就是利用Word 宏的功能。简而言之,就是用程序代替你设置文字的大小,标题的操作。而执行这段程序只需秒秒钟的时间。这段程序就叫做宏。所以,下面就是那段一键化的代码。

    这篇文章的由来:虽然网上有各种格式化粘贴文字的宏,但不能针对特定网站。例如,我想把百度百科的全部内容全部复制粘贴到Word,用网上百度到的宏,只能把它全部整理成一种格式(eg:五号字体,但没标题)。所以,下面的宏,是针对百度百科的,且已经稍作修改,可以格式化一般网站上的文字。你如果稍作修改,也能适应特定的网站,也可以适应一般的网站。如果你想需要将维基百科上的内容复制粘贴且打印的话,直接选择Adobe Acrobat Printer,Printer将自动设置好了字体大小,标题,换行。(如果你装了Adobe Acrobat 软件,一般情况是有的Printer的,没有就是Ghost系统没有一些服务o(╯□╰)o)


已经有的功能:删除段前距,段后距,行距(这样打印就不浪费纸)。正文设置为五号,这样打印出来的字,既不会太大,也不会太小。按Word已经有的标题格式,重新设置标题,也可以略修改,按自己的需求设置。将所有的字体颜色设置为黑色。正文字体大小和标题均可以按自己的需求设置。
没有的功能/Bug/希望能增加的功能:标题设置后的效果和手动点标题设置的效果不一样。将百度百科的内容复制粘贴过来,标题2,标题3就已经是Word内建的标题了,所以标题2,标题3不好设置,需手工设置。因为我的打印文档已经默认设置好页边距,和页脚,所以下面的代码没有页边距和页脚的设置。我希望增加自动插入页眉的功能。


下面是宏代码:

Sub 百度百科一键整理()
'
' 百度百科一键整理 宏
'2013年12月19日,星期四。
'
'
'
    '---------替换空格------
    Selection.WholeStory
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = " "
        .Replacement.Text = " "
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchByte = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
' 替换全角空格
    Selection.WholeStory
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = ""
        .Replacement.Text = "  "
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchByte = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
'---------替换换行------
    Selection.WholeStory
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = "^l"
        .Replacement.Text = "^p"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchByte = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    
    
    '删除“编辑”两个字。可能会多删除,但一般是不会的。
    Selection.WholeStory
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = "编辑"
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchByte = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    
    
    
    
    
    '增加新段落的缩进
    Selection.WholeStory
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = "^p"
        .Replacement.Text = "^p^t"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchByte = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    
    
    
    '修改标题1, (因为标题2, 3系统已经默认修改好了)
    Selection.WholeStory
    Selection.Find.ClearFormatting
    Selection.Find.Font.Size = 17 '有时候好像是13.5,所以下面还有一个类似的,只不过是13.5
    Selection.Find.Replacement.ClearFormatting
    Selection.Find.Replacement.Style = ActiveDocument.Styles("标题 1")
    With Selection.Find.Replacement.Font
        .Size = 12
    End With
    With Selection.Find.Replacement.ParagraphFormat
        .SpaceBeforeAuto = False
        .SpaceAfterAuto = False
        .Alignment = wdAlignParagraphCenter
        .WordWrap = True
    End With
    Selection.Find.Replacement.ParagraphFormat.TabStops.ClearAll
    With Selection.Find.Replacement.ParagraphFormat
        With .Shading
            .Texture = wdTextureNone
            .ForegroundPatternColor = wdColorBlack
            .BackgroundPatternColor = wdColorBlack
        End With
        .Borders.Shadow = False
    End With
    With Selection.Find
        .Text = ""
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindContinue
        .Format = True
        .MatchCase = False
        .MatchWholeWord = False
        .MatchByte = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    Selection.EscapeKey
'修改标题1, (因为标题2, 3系统已经默认修改好了)
    Selection.WholeStory
    Selection.Find.ClearFormatting
    Selection.Find.Font.Size = 13.5 '有时候好像是13.5,所以下面还有一个类似的,只不过是13.5
    Selection.Find.Replacement.ClearFormatting
    Selection.Find.Replacement.Style = ActiveDocument.Styles("标题 1")
    With Selection.Find.Replacement.Font
        .Size = 12
    End With
    With Selection.Find.Replacement.ParagraphFormat
        .SpaceBeforeAuto = False
        .SpaceAfterAuto = False
        .Alignment = wdAlignParagraphCenter
        .WordWrap = True
    End With
    Selection.Find.Replacement.ParagraphFormat.TabStops.ClearAll
    With Selection.Find.Replacement.ParagraphFormat
        With .Shading
            .Texture = wdTextureNone
            .ForegroundPatternColor = wdColorBlack
            .BackgroundPatternColor = wdColorBlack
        End With
        .Borders.Shadow = False
    End With
    With Selection.Find
        .Text = ""
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindContinue
        .Format = True
        .MatchCase = False
        .MatchWholeWord = False
        .MatchByte = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    Selection.EscapeKey
    
    '修改正文,将    '将 七号 改为 五号
    Selection.WholeStory
    Selection.Find.ClearFormatting
    Selection.Find.Font.Size = 7
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find.Replacement.Font
        .Size = 10.5
    End With
    With Selection.Find
        .Text = ""
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindContinue
        .Format = True
        .MatchCase = False
        .MatchWholeWord = False
        .MatchByte = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    
    
    '删除“编辑”之后,还有一个空行。,仅替换一次。
    Selection.HomeKey Unit:=wdStory
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = "^p^t"
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchByte = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute
    With Selection
        If .Find.Forward = True Then
            .Collapse Direction:=wdCollapseStart
        Else
            .Collapse Direction:=wdCollapseEnd
        End If
        .Find.Execute Replace:=wdReplaceOne
        If .Find.Forward = True Then
            .Collapse Direction:=wdCollapseEnd
        Else
            .Collapse Direction:=wdCollapseStart
        End If
        .Find.Execute
    End With
    
    
        ' 删除行距、段距 宏
'-------删除段前距--------
 Selection.WholeStory
    With Selection.ParagraphFormat
        .LeftIndent = CentimetersToPoints(0)
        .RightIndent = CentimetersToPoints(0)
        .SpaceBefore = 0
        .SpaceBeforeAuto = False
        .SpaceAfterAuto = False
        .Alignment = wdAlignParagraphJustify
        .WidowControl = False
        .KeepWithNext = False
        .KeepTogether = False
        .PageBreakBefore = False
        .NoLineNumber = False
        .Hyphenation = True
        .FirstLineIndent = CentimetersToPoints(0)
        .OutlineLevel = wdOutlineLevelBodyText
        .CharacterUnitLeftIndent = 0
        .CharacterUnitRightIndent = 0
        .CharacterUnitFirstLineIndent = 0
        .LineUnitBefore = 0
        .MirrorIndents = False
        .TextboxTightWrap = wdTightNone
        .AutoAdjustRightIndent = True
        .DisableLineHeightGrid = False
        .FarEastLineBreakControl = True
        .WordWrap = True
        .HangingPunctuation = True
        .HalfWidthPunctuationOnTopOfLine = False
        .AddSpaceBetweenFarEastAndAlpha = True
        .AddSpaceBetweenFarEastAndDigit = True
        .BaseLineAlignment = wdBaselineAlignAuto
    End With
    
    '------删除段后距---------
    Selection.WholeStory
    With Selection.ParagraphFormat
        .LeftIndent = CentimetersToPoints(0)
        .RightIndent = CentimetersToPoints(0)
        .SpaceBefore = 0
        .SpaceBeforeAuto = False
        .SpaceAfter = 0
        .SpaceAfterAuto = False
        .Alignment = wdAlignParagraphJustify
        .WidowControl = False
        .KeepWithNext = False
        .KeepTogether = False
        .PageBreakBefore = False
        .NoLineNumber = False
        .Hyphenation = True
        .FirstLineIndent = CentimetersToPoints(0)
        .OutlineLevel = wdOutlineLevelBodyText
        .CharacterUnitLeftIndent = 0
        .CharacterUnitRightIndent = 0
        .CharacterUnitFirstLineIndent = 0
        .LineUnitBefore = 0
        .LineUnitAfter = 0
        .MirrorIndents = False
        .TextboxTightWrap = wdTightNone
        .AutoAdjustRightIndent = True
        .DisableLineHeightGrid = False
        .FarEastLineBreakControl = True
        .WordWrap = True
        .HangingPunctuation = True
        .HalfWidthPunctuationOnTopOfLine = False
        .AddSpaceBetweenFarEastAndAlpha = True
        .AddSpaceBetweenFarEastAndDigit = True
        .BaseLineAlignment = wdBaselineAlignAuto
    End With
    
    '--------删除行距-------
    Selection.WholeStory
    With Selection.ParagraphFormat
        .LeftIndent = CentimetersToPoints(0)
        .RightIndent = CentimetersToPoints(0)
        .SpaceBefore = 0
        .SpaceBeforeAuto = False
        .SpaceAfter = 0
        .SpaceAfterAuto = False
        .LineSpacingRule = wdLineSpaceAtLeast
        .LineSpacing = 12
        .Alignment = wdAlignParagraphJustify
        .WidowControl = False
        .KeepWithNext = False
        .KeepTogether = False
        .PageBreakBefore = False
        .NoLineNumber = False
        .Hyphenation = True
        .FirstLineIndent = CentimetersToPoints(0)
        .OutlineLevel = wdOutlineLevelBodyText
        .CharacterUnitLeftIndent = 0
        .CharacterUnitRightIndent = 0
        .CharacterUnitFirstLineIndent = 0
        .LineUnitBefore = 0
        .LineUnitAfter = 0
        .MirrorIndents = False
        .TextboxTightWrap = wdTightNone
        .AutoAdjustRightIndent = True
        .DisableLineHeightGrid = False
        .FarEastLineBreakControl = True
        .WordWrap = True
        .HangingPunctuation = True
        .HalfWidthPunctuationOnTopOfLine = False
        .AddSpaceBetweenFarEastAndAlpha = True
        .AddSpaceBetweenFarEastAndDigit = True
        .BaseLineAlignment = wdBaselineAlignAuto
    End With
    
    
    
    
    
    '字体颜色处理
    Selection.WholeStory
    Selection.Font.Color = wdColorBlack
    
    
    
End Sub

     关于如何使用Word宏,百度,或者“ http://wenku.baidu.com/link?url=zP5Ckji5u6mrfLIgU09Ia3DISQA_Dhn7vt033k8b3ISxpTU9yoTNeSeIAa2g404ZlK1k52p9SlXSsCeMqTQY1Km5UlTbW9b0Y7KwK-TG0je ”,虽然讲的不是很好。

欢迎大家提出新的需求,举出bug,解决方案,Idea!
Ps:这代码不是手写的,是用“宏录制”功能录制的。我虽然是计算机专业的,但没有Word相关课程,且一般计算机专业的也没有Word相关课程。(⊙o⊙)…

欢迎转载(转载请说明出处)!



消息 优快云首页 发布文章 【数据驱动】【航空航天结构的高效损伤检测技术】一种数据驱动的结构健康监测(SHM)方法,用于进行原位评估结构健康状态,即损伤位置和程度,在其中利用了选定位置的引导式兰姆波响应(Matlab代码实现) 99 100 摘要:会在推荐、列表等场景外露,帮助读者快速了解内容,支持一键将正文前 256 字符键入摘要文本框 0 256 AI提取摘要 您已同意GitCode 用户协议 和 隐私政策,我们会为您自动创建账号并备份文章至我的项目。 活动 话题 共 0 字 意见反馈内容概要:本文研究了在湍流天气条件下,无人机发生发动机故障时的自动着陆问题,提出了一种多级适配控制策略,并通过Matlab进行仿真代码实现。该策略旨在提升无人机在极端环境下的安全着陆能力,重点解决了气流干扰与动力失效双重挑战下的姿态稳定与轨迹规划问题。研究涵盖了故障检测、控制系统重构、自适应调整及安全着陆路径生成等关键技术环节,验证了所提方法在复杂气象条件下的有效性与鲁棒性。; 适合人群:具备一定无人机控制、自动控制理论基础及Matlab编程能力的科研人员、研究生以及从事航空航天、智能控制领域的工程技术人员。; 使用场景及目标:①用于无人机故障应急控制系统的设计与仿真;②支持复杂环境下无人机动态响应分析与控制算法开发;③为飞行器自主安全着陆技术提供解决方案参考。; 阅读建议:建议结合Matlab代码与控制理论深入理解多级适配机制,重点关注故障识别与控制切换逻辑,可通过修改仿真参数测试不同湍流强度下的系统表现,以加深对算法鲁棒性的认识。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值