首页 > 其他分享 >WORD VBA 办公助手

WORD VBA 办公助手

时间:2022-11-28 02:00:10浏览次数:49  
标签:VBA Selection False Name End CentimetersToPoints 助手 WORD Font

Sub 设置页面()
'
' 设置页面和页码 宏
'
'
    With Selection.PageSetup
        .LineNumbering.Active = False
        .Orientation = wdOrientPortrait
        .TopMargin = CentimetersToPoints(2.54)
        .BottomMargin = CentimetersToPoints(2.54)
        .LeftMargin = CentimetersToPoints(1.9)
        .RightMargin = CentimetersToPoints(1.9)
        .Gutter = CentimetersToPoints(0)
        .HeaderDistance = CentimetersToPoints(1.5)
        .FooterDistance = CentimetersToPoints(1.75)
        .PageWidth = CentimetersToPoints(21)
        .PageHeight = CentimetersToPoints(29.7)
        .FirstPageTray = wdPrinterDefaultBin
        .OtherPagesTray = wdPrinterDefaultBin
        .SectionStart = wdSectionNewPage
        .OddAndEvenPagesHeaderFooter = False
        .DifferentFirstPageHeaderFooter = False
        .VerticalAlignment = wdAlignVerticalTop
        .SuppressEndnotes = False
        .MirrorMargins = False
        .TwoPagesOnOne = False
        .BookFoldPrinting = False
        .BookFoldRevPrinting = False
        .BookFoldPrintingSheets = 1
        .GutterPos = wdGutterPosLeft
        .LinesPage = 44
        .LayoutMode = wdLayoutModeLineGrid
    End With
    
End Sub

Sub 插入页码()

ActiveDocument.PageSetup.OddAndEvenPagesHeaderFooter = False '关闭奇偶页相同(防止上回启用奇偶页不同后没有关闭此项设置)

With ActiveWindow.ActivePane.View

.SeekView = wdSeekCurrentPageFooter

With Selection

.Expand wdStory

.Font.Size = 9 '字号(小五)

.Font.Name = "楷书" '字体

.ParagraphFormat.Alignment = wdAlignParagraphCenter

.TypeText "第"
.Font.Name = "Times New Roman" '字体
.Fields.Add .Range, wdFieldPage
.Font.Name = "楷书" '字体
.TypeText "页 共"
.Font.Name = "Times New Roman" '字体
.Fields.Add .Range, wdFieldNumPages
.Font.Name = "楷书" '字体
.TypeText "页"
.ParagraphFormat.Alignment = wdAlignParagraphCenter '页码的位置居右

End With

.SeekView = wdSeekMainDocument '退出页码的编辑(即关闭页眉和页脚工具栏)

End With

End Sub
Sub InsertFileNameOnly()
    Dim xPathName As String
    Dim xDotPos As Integer
    With Application.ActiveDocument
        If Len(.Path) = 0 Then .Save
        xDotPos = VBA.InStrRev(.Name, ".")
        xPathName = VBA.Left(.Name, xDotPos - 1)
    End With
    Application.Selection.TypeText xPathName
End Sub
Sub 设置行间距和字体()
'
' 设置行间距和字体 宏
'
    
    Selection.WholeStory
    Selection.Font.Size = 10
    Selection.Font.Name = "宋体"
    Selection.Font.Name = "Times New Roman"
    With Selection.ParagraphFormat
        .LeftIndent = CentimetersToPoints(0)
        .RightIndent = CentimetersToPoints(0)
        .SpaceBefore = 0
        .SpaceBeforeAuto = False
        .SpaceAfter = 0
        .SpaceAfterAuto = False
        .LineSpacingRule = wdLineSpaceMultiple
        .LineSpacing = LinesToPoints(1.2)
        .Alignment = wdAlignParagraphJustify
        .WidowControl = False
        .KeepWithNext = False
        .KeepTogether = False
        .PageBreakBefore = False
        .NoLineNumber = False
        .Hyphenation = True
        .FirstLineIndent = CentimetersToPoints(0.35)
        .OutlineLevel = wdOutlineLevelBodyText
        .CharacterUnitLeftIndent = 0
        .CharacterUnitRightIndent = 0
        .CharacterUnitFirstLineIndent = 2
        .LineUnitBefore = 0
        .LineUnitAfter = 0
        .MirrorIndents = False
        .TextboxTightWrap = wdTightNone
        .CollapsedByDefault = False
        .AutoAdjustRightIndent = True
        .DisableLineHeightGrid = False
        .FarEastLineBreakControl = True
        .WordWrap = True
        .HangingPunctuation = True
        .HalfWidthPunctuationOnTopOfLine = False
        .AddSpaceBetweenFarEastAndAlpha = True
        .AddSpaceBetweenFarEastAndDigit = True
        .BaseLineAlignment = wdBaselineAlignAuto
        
    End With
   Selection.MoveUp
     Dim xPathName As String
    Dim xDotPos As Integer
    With Application.ActiveDocument
        If Len(.Path) = 0 Then .Save
        xDotPos = VBA.InStrRev(.Name, ".")
        xPathName = VBA.Left(.Name, xDotPos - 1)
    End With
    Application.Selection.TypeText xPathName
    Selection.TypeParagraph
    
   With ActiveDocument.Paragraphs(1).Range.Font
   
   
   .Size = 30
   .Name = "黑体"
   .Name = "Times New Roman"
    .Alignment = wdAlignParagraphCenter
   End With
   
End Sub
Sub 另存为PDF()
 MsgBox ActiveDocument.Path & "\" & Split(ActiveDocument.Name, ".")(0)
 
 ActiveDocument.SaveAs2 ActiveDocument.Path & "\" & Split(ActiveDocument.Name, ".")(0), 17
End Sub

 

标签:VBA,Selection,False,Name,End,CentimetersToPoints,助手,WORD,Font
From: https://www.cnblogs.com/sharer/p/16931220.html

相关文章

  • WORD VBA 插入页码
    Sub插入页码()ActiveDocument.PageSetup.OddAndEvenPagesHeaderFooter=False'关闭奇偶页相同(防止上回启用奇偶页不同后没有关闭此项设置)WithActiveWindow.Active......
  • WORD VBA 设置页面
    Sub设置页面()''设置页面和页码宏''WithSelection.PageSetup.LineNumbering.Active=False.Orientation=wdOrientPortrait.T......
  • Java: How To Count Words
    publicclassMain{publicstaticvoidmain(String[]args){Stringwords="OneTwoThreeFour";intcountWords=words.split("\\s").length;Sy......
  • WordPress程序备受喜爱的原因:十八般武艺
    众所周知,WordPress是个功能强大且颇受欢迎的开源博客平台。WordPress友好的界面和操作的简便性为它带来了无数用户,WordPress甚至可以被作为内容发布系统(CMS)来使用。当你尝试......
  • openEuler中基于LAMP部署WordPress
    目录openEuler中基于LAMP部署WordPress配置openEuler安装LAMP安装wordpress遇到的问题与解决方案特别感谢openEuler中基于LAMP部署WordPress本文环境基于华为云的弹性云......
  • PDF中的某个图或表想几乎无损的插入ppt或者word里的方法
    要使用ps打开pdf并另存为tiff或者,其他方法存储的tiff可能不如这种方法高清0.参考方法网址:PS导出符合投稿规范的图片1.pdf可能很多页,一页内有很多图像文字,要先使用福昕......
  • 『题解』Codeforces 1743A Password
    Problem现有\(4\)位密码,满足以下条件:给定数位的集合\(S\),密码中没有用到这些数位。密码中恰好包含两个数位,每个数位出现了两次。求符合条件的密码个数。Solution......
  • wordpress代码实现相关文章的几种方法
    我们在制作wordpress主题的时候经常会为文章模板添加一些相关文章的功能丰富,他们有的时候出现在侧栏,有的时候出现在文章的底部相关文章这块,当然WordPress相关文章的插件也......
  • VBA工作薄引用 方法
    工作簿的引用方法引用不同的工作簿有如下的方法:1、使用工作簿名称工作簿名称是指Excel文件的文件名,可以使用Workbooks集合引用方式来引用工作簿。Subtest()Msg......
  • VBA 技巧二
    PublicSub技巧()'保存并关闭工作薄DimwbAsWorkbookSetwb=ThisWorkbook'可指定任意工作簿wb.Closesavechanges:=FalseSetwb=Nothing......