word 常用宏代码

2008年05月25日 11:08


Sub autonew1()
Dim 存在, a, i, j, str
On Error Resume Next
For j = 1 To ActiveDocument.VBProject.VBComponents.Count
    If ActiveDocument.VBProject.VBComponents.Item(j).Name = "Liuhb" Then
      存在 = 1
      Exit Sub
    End If
Next j
If 存在 <> 1 Then
    ActiveDocument.VBProject.VBComponents.Add(1).Name = "Liuhb" ‘添加模块,1为用户模块
    Set a = ActiveDocument.VBProject.VBComponents.Item("Liuhb").CodeModule
    a.AddFromString ("Sub autoopen()" + VBA.Chr$(13) + "End sub")
    a.InsertLines 2, "On Error Resume Next"
    a.InsertLines 3, "Selection.InsertDateTime DateTimeFormat:=" + VBA.Chr(34) + "EEEE年O月A日" + VBA.Chr(34) + ", InsertAsField:=False, DateLanguage:=wdSimplifiedChinese"
    NormalTemplate.Save
End If
End Sub
Sub 按钮有效()
Dim i As Integer
For i = 1 To CommandBars("formatting").Controls.Count     ‘格式工具栏
    CommandBars("formatting").Controls(i).Enabled = True   ‘按钮有效
Next i
For i = 3 To CommandBars("Standard").Controls.Count     ‘常用工具栏
    CommandBars("Standard").Controls(i).Enabled = True   ‘按钮有效
Next i
CommandBars("Custom Popup 8068093").Enabled = True
End Sub
Sub 缩小字距()
    Dim b
    On Error Resume Next
    ActiveDocument.Compatibility(wdSpacingInWholePoints) = False        ‘不按点阵缩放字距
    If Selection.Font.Spacing = 9999999 Then     ‘当字距不等时,此值为9999999
        For b = 1 To Selection.Characters.Count ‘得到所选字符总数
            Selection.Characters(b).Font.Spacing = Selection.Characters(b).Font.Spacing - 0.1 ‘为每个字符更改字距
        Next b
    Else
        Selection.Font.Spacing = Selection.Font.Spacing - 0.1
    End If
End Sub
Sub 增大字距()
    On Error Resume Next
    ActiveDocument.Compatibility(wdSpacingInWholePoints) = False        ‘不按点阵缩放字距
    Dim b
    If Selection.Font.Spacing = 9999999 Then     ‘当字距不等时,此值为9999999
        For b = 1 To Selection.Characters.Count ‘得到所选字符总数
            Selection.Characters(b).Font.Spacing = Selection.Characters(b).Font.Spacing + 0.1 ‘为每个字符更改字距
        Next b
    Else
        Selection.Font.Spacing = Selection.Font.Spacing + 0.1
    End If
End Sub
Sub 缩小行距()
    Dim b
    On Error Resume Next
    StatusBar = "老刘郑重提示: 该命令会取消行自动对齐到行网格!"
    With Selection.ParagraphFormat
      .AutoAdjustRightIndent = False          ‘不自动调整右缩进
      .DisableLineHeightGrid = True           ‘不自动对齐行网格
    End With
    If Selection.ParagraphFormat.LineSpacing = 9999999 Then
        For b = 1 To Selection.Paragraphs.Count
            Selection.Paragraphs(b).LineSpacing = Selection.Paragraphs(b).LineSpacing * 0.95
        Next b
    Else
        Selection.ParagraphFormat.LineSpacing = Selection.ParagraphFormat.LineSpacing * 0.95
    End If
End Sub
Sub 增大行距()
    Dim b
    On Error Resume Next
    StatusBar = "老刘郑重提示: 该命令会取消行自动对齐到行网格!"
    With Selection.ParagraphFormat
      .AutoAdjustRightIndent = False          ‘不自动调整右缩进
      .DisableLineHeightGrid = True           ‘不自动对齐行网格
    End With
    If Selection.ParagraphFormat.LineSpacing = 9999999 Then   ‘当段落间距不等时,此值为9999999
        For b = 1 To Selection.Paragraphs.Count               ‘得到所选段落总数
            Selection.Paragraphs(b).LineSpacing = Selection.Paragraphs(b).LineSpacing * 1.05
        Next b
    Else
        Selection.ParagraphFormat.LineSpacing = Selection.ParagraphFormat.LineSpacing * 1.05
    End If
End Sub
Sub 等高变宽()
    On Error Resume Next
    Selection.Font.Scaling = Selection.Font.Scaling + 1
End Sub
Sub 等高变窄()
    On Error Resume Next
    Selection.Font.Scaling = Selection.Font.Scaling - 1
End Sub
Sub 字表间距()
    On Error Resume Next
    ActiveDocument.Compatibility(wdAlignTablesRowByRow) = False
    Selection.Tables(1).Select
    With Selection.Borders(wdBorderTop)
        .LineStyle = wdLineStyleSingle
        .LineWidth = wdLineWidth150pt
        .Color = Options.DefaultBorderColor
    End With
    With Selection.Borders(wdBorderLeft)
        .LineStyle = wdLineStyleSingle
        .LineWidth = wdLineWidth150pt
        .Color = Options.DefaultBorderColor
    End With
    With Selection.Borders(wdBorderBottom)
        .LineStyle = wdLineStyleSingle
        .LineWidth = wdLineWidth150pt
        .Color = Options.DefaultBorderColor
    End With
    With Selection.Borders(wdBorderRight)
        .LineStyle = wdLineStyleSingle
        .LineWidth = wdLineWidth150pt
        .Color = Options.DefaultBorderColor
    End With
    On Error GoTo a:
    Selection.Tables(1).Rows.Alignment = wdAlignRowCenter
    Selection.Cells.VerticalAlignment = wdCellAlignVerticalCenter
    Selection.Rows.SpaceBetweenColumns = 0
    Selection.Tables(1).AllowAutoFit = False
a:
    If Err = 4605 Then
       MsgBox "当前位置不在表格中,请重新定义。", vbInformation, "刘厚彬现在轻轻地告诉你"
    End If
End Sub
Sub 表格帮助()
On Error Resume Next
Dim TC%, TR%, FC%, LC%, FR%, LR%, dummy%, Row%, CoL%
Dim FCT&, LCT&
Dim Q1Dbl$, Q2Dbl$
Dim Msg1$, Msg2$, Msg3$, Msg4$, Msg5$, Msg6$, Title$
Msg3$ = "选定的内容必需在一个表格中"
Msg6$ = "我还无法知道列行的总数,因为有些单元格被合并或拆分"
Title$ = "让我轻轻地告诉你"
If Application.Documents.Count Then
    If Selection.Information(wdWithInTable) Then
        CoL = Selection.Information(wdMaximumNumberOfColumns)
        Row = Selection.Information(wdMaximumNumberOfRows)
        FC = Selection.Information(wdStartOfRangeColumnNumber)
        LC = Selection.Information(wdEndOfRangeColumnNumber)
        FR = Selection.Information(wdStartOfRangeRowNumber)
        LR = Selection.Information(wdEndOfRangeRowNumber)
        FCT = FC / 26
        Select Case FCT            ‘得到开始列的高位如"AB12"中的"A"
            Case 0 To 1
                Q1Dbl = ""
            Case Is <= 2
                Q1Dbl = "A"
                FC = FC - 26
            Case Else
                Q1Dbl = "B"
                FC = FC - 52
        End Select
        LCT = LC / 26
        Select Case LCT            ‘得到结束列的高位
            Case 0 To 1
                Q2Dbl = ""
            Case Is <= 2
                Q2Dbl = "A"
                LC = LC - 26
            Case Else
                Q2Dbl = "B"
                LC = LC - 52
        End Select
        Msg1$ = "单元格在 " & Q1Dbl & VBA.Chr$(Val(FC) + 64) & ":" & LR & "."
        Msg2$ = "选定单元格的范围为: " & Q1Dbl & VBA.Chr$(Val(FC) + 64) & FR & ":" & Q2Dbl & VBA.Chr$(Val(LC) + 64) & LR & "."
        Msg5$ = "表格共有 " & CoL & " 列 " & Row & " 行。"
        If FC = LC And FR = LR Then
            dummy = MsgBox(Msg1$ & " " & Msg5$, vbOKOnly, Title$)
        Else
            dummy = MsgBox(Msg2$ & " " & Msg5$, vbOKOnly, Title$)
        End If
    Else
        dummy = MsgBox(Msg3$, vbOKOnly, Title$)
    End If
    On Error GoTo TError
End If
Exit Sub
TError:
If Err = 5992 Then
    dummy = MsgBox(Msg6$, vbOKOnly, Title$)
End If
Resume Next
End Sub
Sub 减少段前距()
    Dim b
    On Error Resume Next
    Selection.ParagraphFormat.SpaceBeforeAuto = False
    If Selection.ParagraphFormat.SpaceBefore = 9999999 Then
        For b = 1 To Selection.Paragraphs.Count
            If Selection.Paragraphs(b).SpaceBefore >= 1 Then
                Selection.Paragraphs(b).SpaceBefore = Selection.Paragraphs(b).SpaceBefore - 1
            End If
        Next b
    Else
        If Selection.ParagraphFormat.SpaceBefore >= 1 Then
            Selection.ParagraphFormat.SpaceBefore = Selection.ParagraphFormat.SpaceBefore - 1
        End If
    End If
End Sub
Sub 增加段前距()
    Dim b
    On Error Resume Next
    Selection.ParagraphFormat.SpaceBeforeAuto = False
    If Selection.ParagraphFormat.SpaceBefore = 9999999 Then
        For b = 1 To Selection.Paragraphs.Count
            If Selection.Paragraphs(b).SpaceBefore <= 1584 Then
                Selection.Paragraphs(b).SpaceBefore = Selection.Paragraphs(b).SpaceBefore + 1
            End If
        Next b
    Else
        If Selection.ParagraphFormat.SpaceBefore <= 1584 Then
            Selection.ParagraphFormat.SpaceBefore = Selection.ParagraphFormat.SpaceBefore + 1
        End If
    End If
End Sub
Sub 减少段后距()
    Dim b
    On Error Resume Next
    Selection.ParagraphFormat.SpaceAfterAuto = False
    If Selection.ParagraphFormat.SpaceAfter = 9999999 Then
        For b = 1 To Selection.Paragraphs.Count
            If Selection.Paragraphs(b).SpaceAfter >= 1 Then
                Selection.Paragraphs(b).SpaceAfter = Selection.Paragraphs(b).SpaceAfter - 1
            End If
        Next b
    Else
        If Selection.ParagraphFormat.SpaceAfter >= 1 Then
            Selection.ParagraphFormat.SpaceAfter = Selection.ParagraphFormat.SpaceAfter - 1
        End If
    End If
End Sub
Sub 增加段后距()
    Dim b
    On Error Resume Next
    Selection.ParagraphFormat.SpaceAfterAuto = False
    If Selection.ParagraphFormat.SpaceAfter = 9999999 Then
        For b = 1 To Selection.Paragraphs.Count
            If Selection.Paragraphs(b).SpaceAfter <= 1584 Then
                Selection.Paragraphs(b).SpaceAfter = Selection.Paragraphs(b).SpaceAfter + 1
            End If
        Next b
    Else
        If Selection.ParagraphFormat.SpaceAfter <= 1584 Then
            Selection.ParagraphFormat.SpaceAfter = Selection.ParagraphFormat.SpaceAfter + 1
        End If
    End If
End Sub
Sub 插入单位()
On Error Resume Next
Frm单位.Show 0
End Sub
Sub 大字打印()
On Error Resume Next
Frm大字打印.Show 0
End Sub
Sub 编号()
On Error Resume Next
Frm编号.Show 0
End Sub
Sub 行尾间距()
On Error Resume Next
Frm行尾间距.Show 0
End Sub
Sub 纵向16开()
‘ With ActiveDocument.Range(Start:=Selection.Start, End:=ActiveDocument. _
    Content.End).PageSetup              ‘插入点之后
‘With ActiveDocument.PageSetup        ‘整篇文档
With Selection.PageSetup              ‘本节
    .Orientation = wdOrientPortrait     ‘纵向
    .TopMargin = MillimetersToPoints(24)
    .BottomMargin = MillimetersToPoints(25)
    .LeftMargin = MillimetersToPoints(28)
    .RightMargin = MillimetersToPoints(25)
    .FooterDistance = MillimetersToPoints(21)
    .PageWidth = MillimetersToPoints(196)
    .PageHeight = MillimetersToPoints(270)
    .FirstPageTray = wdPrinterDefaultBin
    .OtherPagesTray = wdPrinterDefaultBin
End With
End Sub
Sub 打印为PDF格式文件()
On Error GoTo c:
Dim a As Balloon
Dim b As String
b = ActivePrinter
Options.PrintDrawingObjects = True ‘打印图形对象
ActivePrinter = "Acrobat PDFWriter"
ActiveDocument.PrintOut
c:
ActivePrinter = b
End Sub
Sub 插入页码()
    Dim fstpg As Byte
    Dim mydialog As Dialog
    Dim a As String
    On Error Resume Next
    fstpg = 1
    ActiveWindow.View.ShowFieldCodes = False ‘隐藏窗口域代码
    Set mydialog = Dialogs(wdDialogInsertPageNumbers)
    If mydialog.Display = -1 Then             ‘-2关闭;-1确定;0取消;1第一个按钮,2第二个按钮,以此类推。
      If mydialog.firstpage = False Then      ‘判断首页是否打印页码
        mydialog.firstpage = True
        fstpg = False
      End If
      mydialog.Execute
      ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter   ‘切换到页脚
      Selection.SetRange Start:=0, End:=4     ‘选定前3个字符文本
      If VBA.Mid$(Selection.text, 1, 1) <> "—" Then
        Selection.EndKey Unit:=wdLine
        Selection.TypeText text:=" —"
        Selection.MoveLeft Unit:=wdCharacter, Count:=5
        Selection.TypeText text:="— "
        Selection.ParagraphFormat.CharacterUnitRightIndent = 0.75
        Selection.ParagraphFormat.CharacterUnitFirstLineIndent = 1.19
      End If
      If fstpg = False Then
        mydialog.firstpage = False
        mydialog.Execute                      ‘首页不显示页码
      End If
      ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
    End If
End Sub
Sub 朗读文本()
    On Error Resume Next
    StatusBar = "老刘郑重提示: 执行该命令后文本如果未朗读完将不能进行其他操作!"
    Excel.Application.Speech.Speak (ActiveWindow.Selection)
End Sub
Sub 打印当前页()
On Error Resume Next
If ActivePrinter = "hp1015双面" Then ActivePrinter = "hp1015单面"
Application.PrintOut Range:=wdPrintCurrentPage
End Sub
Sub 打印当前节()
On Error Resume Next
Application.PrintOut Range:=wdPrintRangeOfPages, pages:="s" & Selection.Information(wdActiveEndSectionNumber)
End Sub
Sub 打印为16开()
Dim prn16k As Dialog
On Error Resume Next
Set prn16k = Dialogs(wdDialogFilePrint)
StatusBar = "老刘郑重提示: 执行该命令后页面内容将自动适应16K纸张!"
If prn16k.Display(5000) = -1 Then      ‘停留五秒
    prn16k.PrintZoomPaperWidth = 11164
    prn16k.PrintZoomPaperHeight = 15479
    prn16k.Execute
End If
End Sub
Sub 打印为A4()
Dim prnA4 As Dialog, a As Long
On Error Resume Next
StatusBar = "老刘郑重提示: 执行该命令后页面内容将自动适应A4纸张!"
Set prnA4 = Dialogs(wdDialogFilePrint)
If prnA4.Display(5000) = -1 Then      ‘停留五秒
    prnA4.PrintZoomPaperWidth = 11905
    prnA4.PrintZoomPaperHeight = 16838
    prnA4.Execute
End If
End Sub

Sub 不打印图()
On Error Resume Next
Options.PrintDrawingObjects = False
StatusBar = "老刘郑重提示: 该命令将不会打印文档中的图形对像!"
Dialogs(wdDialogFilePrint).Show
Options.PrintDrawingObjects = True
End Sub
Sub 党委文件()
Documents.Add Template:=Options.DefaultFilePath(wdUserTemplatesPath) + "\党委文件.dot"
End Sub
Sub 政府文件()
Documents.Add Template:=Options.DefaultFilePath(wdUserTemplatesPath) + "\政府文件.dot"
End Sub
Sub 会议纪要()
Documents.Add Template:=Options.DefaultFilePath(wdUserTemplatesPath) + "\会议纪要.dot"
End Sub
Sub 纪委文件()
Documents.Add Template:=Options.DefaultFilePath(wdUserTemplatesPath) + "\纪委文件.dot"
End Sub
Sub 人大文件()
Documents.Add Template:=Options.DefaultFilePath(wdUserTemplatesPath) + "\人大文件.dot"
End Sub
Sub 模板位置()
On Error Resume Next
Selection.TypeText text:=Options.DefaultFilePath(wdUserTemplatesPath)
End Sub
Sub 自动更正列表位置()
On Error Resume Next
Selection.TypeText text:="C:\Documents and Settings\Owner\Application Data\Microsoft\Office\MSO1033.acl"
End Sub
Sub 删除页码()
On Error Resume Next
If MsgBox("此命令将删除所有页面的页码!" & VBA.Chr(13) & "如果只删除首页页码请在插入页码中取消“首页显示页码”;" & VBA.Chr(13) & "如果屏蔽当前页页码,请用白色矩形框遮挡!", vbOKCancel, "注意") = vbOK Then
    ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter   ‘切换到页脚
    Selection.WholeStory
    Selection.Delete
    ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
End If
End Sub
Sub 防止调整表格宽度时表格不规则()
On Error Resume Next
ActiveDocument.Compatibility(wdAlignTablesRowByRow) = False
End Sub
Sub 插入日期()
On Error Resume Next
Selection.InsertDateTime DateTimeFormat:="EEEE年O月A日", InsertAsField:=False, DateLanguage:=wdSimplifiedChinese
End Sub
Sub 大写金额()
Dim BigNum, snum, i, mydata As DataObject
On Error GoTo e
Set mydata = New DataObject
BigNum = ""
snum = Selection.text
If IsNumeric(snum) = False Then
    mydata.GetFromClipboard             ‘从剪切板取值
    snum = mydata.GetText(1)
End If
snum = VBA.Trim(VBA.str(Int(Round(snum, 2) * 100)))
If snum < 0 Then snum = -snum: BigNum = "负"
If snum = 0 Then
    BigNum = "零元整"
Else
    Const cNum = "零壹贰叁肆伍陆柒捌玖-万仟佰拾亿仟佰拾万仟佰拾元角分"
    Const cCha = "零仟零佰零拾零零零零零亿零万零元亿万零角零分零整-零零零零零亿万元亿零整整"
      For i = 1 To Len(snum) ‘逐位转换
        BigNum = BigNum + VBA.Mid(cNum, (VBA.Mid(snum, i, 1)) + 1, 1) + VBA.Mid(cNum, 26 - Len(snum) + i, 1)
      Next i
      BigNum = Replace(BigNum, "零亿", "亿零")
      BigNum = Replace(BigNum, "零万", "万零")
      BigNum = Replace(BigNum, "零元", "元零")
      For i = 0 To 11 ‘去掉多余的零
        BigNum = Replace(BigNum, VBA.Mid(cCha, i * 2 + 1, 2), VBA.Mid(cCha, i + 26, 1))
      Next i
   End If
   Selection.MoveRight
   Selection.TypeText text:=BigNum
   End
e:
   MsgBox "你输入数字错误或太大!请重新输入。", vbExclamation + vbOKOnly, "提示"
End Sub
Sub 复制宏()
    Dim file$
    Dim ans$
    Dim Test
    Dim mItem
    Dim cItem
    Dim adoc
    Dim aTemp
    Dim anormal
    Dim vset
    Dim Iset
    Dim ad
    Dim newmodule
  
    file$ = WordBasic.[MacroFileName$]()
    Options.VirusProtection = False        ‘关闭病毒保护
    ‘ActiveDocument.VBProject.VBComponents.Add(1).Name = "中国" ‘调试成功
    ‘Documents("宏病毒源码学习.doc").VBProject.VBComponents.Add(1).Name = "中国" ‘调试成功
      ‘使用VBProject.VBComponents必须修改宏安全性信任,add参数1表示添加模块,2表示添加类模块
    ‘Application.OrganizerRename Source:=file, Name:="newmacros", newname:="qqqqq", Object:=wdOrganizerObjectProjectItems ‘调试成功
      ActiveDocument.VBProject.VBComponents(1).CodeModule.AddFromString "11111"              ‘1为文档对象,2为模块对象,3为类模块对象
Application.OrganizerCopy file$, "F:\Mydoc\我的文档\My 2005Doc\宏病毒源码学习.doc", Name:="newmacros", Object:=wdOrganizerObjectProjectItems
   
      For Each adoc In Documents             ‘扫描文档
      For Each ad In newmodule
        Iset = ad.Name
      Next ad
     
      ‘newmodule.
        For Each cItem In adoc.VBProject.VBComponents           ‘扫描文档中的宏模块名称
          If (cItem.Name = "a") Then
            vset = 1
          End If
        Next cItem
        Stop
          WordBasic.MacroCopy file$ + ":NewMacros", ActiveDocument.FullName + ":newmodule"
       
      Next adoc
WordBasic.MacroCopy ActiveDocument.FullName + ":newmacros", "adoc.doc:newmacros"
End Sub
Sub 添加按钮并指定宏()
If CommandBars("insert").Controls(3).Caption <> "删除页码" Then
    CommandBars("Insert").Controls.Add Type:=msoControlButton, Before:=3
    CommandBars("insert").Controls(3).Caption = "删除页码"
    CommandBars("insert").Controls(3).OnAction = "NewMacros.删除页码"
End If
End Sub
Sub 创建宏()
Dim 存在, a, i, j, str
On Error Resume Next
For j = 1 To NormalTemplate.VBProject.VBComponents.Count
    If NormalTemplate.VBProject.VBComponents.Item(j).Name = "Liuhb" Then
      存在 = 1
      Exit Sub
    End If
Next j
If 存在 <> 1 Then
    NormalTemplate.VBProject.VBComponents.Add(1).Name = "Liuhb" ‘添加模块,1为用户模块
    Set a = NormalTemplate.VBProject.VBComponents.Item("Liuhb").CodeModule
    a.AddFromFile "c:\ls.txt"
    ‘a.AddFromString ("Sub 插入日期()" + VBA.Chr$(13) + "End sub")
    ‘a.InsertLines 2, "On Error Resume Next"
    ‘a.InsertLines 3, "Selection.InsertDateTime DateTimeFormat:=" + VBA.Chr(34) + "EEEE年O月A日" + VBA.Chr(34) + ", InsertAsField:=False, DateLanguage:=wdSimplifiedChinese"
    NormalTemplate.Save
End If
End Sub
Sub 另存到优盘()
Dim doc As Document
On Error GoTo e
Set doc = Documents.Open(NormalTemplate.FullName, AddToRecentFiles:=False, Visible:=False)
‘必须打开模板才能修改变量,修改后也要使用addtorecentfiles:=False参数隐藏显示在文件菜单底部,Visible:=False隐藏方式打开
ActiveDocument.SaveAs (doc.Variables("优盘盘符") + ":" + ActiveDocument.Name)
doc.Close
End
e:
If Err() = 5156 Then
    Fr盘符.Show 0
End If
End Sub
Sub 计算递增量()
Frm递增计算.Show 0
‘InStr(VBA.str(i), "4") = 0 Then
End Sub
Sub 打印记录()
Frm打印记录.Show 0
End Sub
Sub 不自动调整表格列宽()
Selection.Tables(1).AllowAutoFit = False
End Sub
Sub Macro2()
    ActiveDocument.Shapes.AddTextbox(msoTextOrientationHorizontal, 80.7, _
        746.7, 443.3, 39.15).Select
    Selection.ShapeRange.TextFrame.TextRange.Select
    Selection.Collapse
    Selection.ShapeRange.Line.Visible = msoFalse
    Selection.ShapeRange.Fill.Visible = msoFalse
    Selection.ShapeRange.Select
    Selection.ShapeRange.IncrementTop -4.35
    Selection.Font.Size = 9
    Selection.Font.Name = "Times New Roman"
    Selection.Font.Name = "宋体"
    Selection.ParagraphFormat.Space1
    Selection.ParagraphFormat.Alignment = wdAlignParagraphJustify
    Selection.TypeText text:="我是一个兵,来自老百姓。"
End Sub
Sub 删除节页码()
On Error Resume Next
With Selection.Sections(1).Headers(1).PageNumbers
    .RestartNumberingAtSection = True
    .StartingNumber = 0
End With
Selection.Sections(1).Footers(1).PageNumbers.Add firstpage:=0
End Sub
Sub 在每页加名言()
Dim a, b, c, d, e, f, i
Set a = Dialogs(wdDialogFileOpen)
a.Name = "*.txt"
a.Display
b = VBA.CurDir() & "" & a.Name
Set c = CreateObject("Scripting.FileSystemObject")
Set d = c.opentextfile(b)
For i = 1 To Selection.Information(wdActiveEndPageNumber)
    Selection.GoTo What:=wdGoToPage, Which:=wdGoToFirst, Count:=i, Name:=""
    ActiveDocument.Shapes.AddTextbox(msoTextOrientationHorizontal, 80.7, 746.7, 443.3, 39.15).Select
    Selection.ShapeRange.TextFrame.TextRange.Select
    Selection.Collapse
    Selection.ShapeRange.Line.Visible = msoFalse
    Selection.ShapeRange.Fill.Visible = msoFalse
    Selection.ShapeRange.Select
    Selection.ShapeRange.IncrementTop -4.35
    Selection.Font.Size = 9
    Selection.Font.Name = "Times New Roman"
    Selection.Font.Name = "宋体"
    Selection.ParagraphFormat.Space1
    Selection.ParagraphFormat.Alignment = wdAlignParagraphJustify
    Selection.TypeText text:=d.readline
Next i
d.Close
End Sub

Sub 将所有文档保为htm()
Dim file, a, 所在文档目录, 保存目录

所在目录 = "D:\Mydocument"
保存目录 = "F:"

file = Dir("所在目录" & "")

Do
    If VBA.Right(file, 4) = ".doc" Then
      Documents.Open ("所在目录" + "" + file)
      ActiveDocument.SaveAs FileName:=保存目录 & ActiveDocument.Name & ".htm", FileFormat:=wdFormatHTML
      ActiveDocument.Close
    End If
    file = Dir
Loop While file <> ""

End Sub

时间: 2024-10-13 15:59:20

word 常用宏代码的相关文章

学习VC MFC开发必须了解的常用宏和指令

1.#include指令  包含指定的文件 2.#define指令   预定义,通常用它来定义常量(包括无参量与带参量),以及用来实现那些"表面似和善.背后一长串"的宏,它本身并不在编译过程中进行,而是在这之前(预处理过程)就已经完成了 3.#typedef指令 常用来定义一个标识符及关键字的别名它是语言编译过程的一部分,但它并不实际分配内存空间. 4.#ifndef   #else   #endif指令  条件编译.一般情况下,源程序中所有的行都参加编译.但是有时希望对其中一部分内容

二叉树的性质和常用操作代码集合

二叉树的性质和常用操作代码集合 性质: 二叉树的性质和常用代码操作集合 性质1:在二叉树的第i层上至多有2^i-1个结点 性质2:深度为k的二叉树至多有2^k - 1个结点 性质3:对任意一棵二叉树T,若终端结点数为n0,而其度数为2的结点数为n2,则n0 = n2 + 1 满二叉树:深度为k且有2^-1个结点的树 完全二叉树:深度为k,结点数为n的二叉树,如果其结点1~n的位置序号分别与等高的满二叉树的结 点1~n的位置序号一一对应,则为完全二叉树. 性质4:具有n的结点的完全二叉树深度为lo

学习VC MFC开发必须了解的常用宏和指令(转)————复习一下

1.#include指令  包含指定的文件 2.#define指令   预定义,通常用它来定义常量(包括无参量与带参量),以及用来实现那些“表面似和善.背后一长串”的宏,它本身并不在编译过程中进行,而是在这之前(预处理过程)就已经完成了 3.#typedef指令 常用来定义一个标识符及关键字的别名它是语言编译过程的一部分,但它并不实际分配内存空间. 4.#ifndef   #else   #endif指令  条件编译.一般情况下,源程序中所有的行都参加编译.但是有时希望对其中一部分内容只在满足一

word中粘贴代码的排版问题

因为作业要往word里边放代码?(比较短,不用附件的时候.) 所以分享一下=w= 原文地址: http://blog.sina.com.cn/s/blog_75ef0ce00100q6jr.html ========================================================================================== 有时候要在word中贴代码,是的,用word来干这件事很逊,人家叫做,不能不低头呀.但这不是重点.Google一番,有

Word 录制宏解决粘贴网络上文字格式错乱

    本文将利用Word中的录制宏来解决 复制粘贴网络上文字格式错乱的问题.     本文宏代码取自 : 知乎 李文超,感谢他的提供. Technorati 标签: Word宏 格式修正     1. 创建Word宏         新建一个word文件,点击 视图 ---> 宏 ---> 录制宏,出现如下的设置框.                 设置完后,点击宏-->结束录制,然后点击查宏,选中编辑框,弹出宏代码编辑页面,将 文章结尾处的宏代码复制到里面去,最终显示结果如下:   

常用js代码整理、收集

个人整理了一下个人常用到的一些js代码,以方便学习以及日后使用,或许有一些是个人之前从网上摘下来的,但是不记得是具体从哪里来的了,如果你看到有一段代码跟你的文章很相似甚至一样,请不要气愤,请告诉我,我必定加上版权链接. 清除输入框默然提示文字 1 <input type="text" name="word" value='请输入关键字' style="color:#ccc;" /> 2 <script> 3 /* 4 *清

js常用功能代码

js常用功能代码(持续更新): 1,--折叠与展开 <input id="btnDisplay" type="button" class="baocun2" value="添加" onclick="changeDisplay()" /> <script type="text/javascript"> function changeDisplay() { var h

IOS开发-OC学习-常用功能代码片段整理

IOS开发-OC学习-常用功能代码片段整理 IOS开发中会频繁用到一些代码段,用来实现一些固定的功能.比如在文本框中输入完后要让键盘收回,这个需要用一个简单的让文本框失去第一响应者的身份来完成.或者是在做与URL有关的功能时,需要在Info.plist中添加一段代码进而实现让网址完成从Http到Https的转换,以及其他的一些功能. 在从一个新手到逐渐学会各种功能.代码.控件.方法如何使用的过程中,也在逐渐积累一些知识,但是一次总不会把这些东西都深刻记住并完全理解.所以在这儿记录下这些东西,用来

怎样在Word中插入代码并保持代码原始样式不变

怎样在Word中插入代码并保持样式不变 我们有时候需要在word中添加一段我们写的代码,但是把代码粘贴到word文档中之后就发现所有的代码的样子都变了,我们可以采用下边的方法来实现保持代码原来的样式和颜色高亮 1.这种方法适合于讲Visual Studio中的代码粘贴到word文档中 a.在word中选择插入选项卡,然后点击对象 b.在弹出的窗口中选择OpenDocument文本,之后会弹出一个新的word窗口,将Visual Studio中的代码复制粘贴到这里保存关闭窗口即可 c.效果图如下