国旅手游网提供好玩的手机游戏和手机必备软件下载,每天推荐精品安卓手游和最新应用软件app,并整理了热门游戏攻略、软件教程、资讯等内容。欢迎收藏

当前位置:国旅手游网攻略软件教程内容

wordvba编程手册[word vba编程]优质

546次浏览 | 2023-05-11 23:48:38 更新
提问:平庸
最佳经验
回答:飘逸

网友采纳答案

网友平庸提问:word vba编程基础知识

很多的程序员都离不开编程的代码,但是对于wordvba肯定有很多的新手不知道常用代码有哪些,所以下面就给你们提供了wordvba编程代码大全,快来一起看看吧。

wordvba编程手册

wordvba编程代码有哪些:

1、删除空行 

Sub 删除空行() 

Dim I As Paragraph, n As Integer 

Application.ScreenUpdating = False 

For Each I In ActiveDocument.Paragraphs 

If Len(Trim(I.Range)) = 1 Then 

I.Range.Delete 

n = n + 1 

End If 

Next 

MsgBox "共删除空白段落" & n & "个" 

Application.ScreenUpdating = True 

End Sub 

2、奇偶页打印 

Sub 奇偶页打印() 

Dim x, j, i As Integer 

On Error Resume Next 

x = ExecuteExcel4Macro("Get.Document(50)") 

For i = 1 To Int(x / 2) + 1 

ActiveWindow.SelectedSheets.PrintOut From:=2 * i - 1, To:=2 * i - 1 

Next i 

If x = 1 Then 

MsgBox "无偶数页" 

Else 

MsgBox "请将打印出的纸张反向装入纸槽中", vbOKOnly, "打印另一面" 

For j = 1 To Int(x / 2) + 1 

ActiveWindow.SelectedSheets.PrintOut From:=2 * j, To:=2 * j 

Next j 

End If 

End Sub  

wordvba编程手册

3、中英文标点互换

Sub 中英文标点互换() 

Dim ChineseInterpunction() As Variant, EnglishInterpunction() As Variant 

Dim myArray1() As Variant, myArray2() As Variant, strFind As String, strRep

As String 

Dim msgResult As VbMsgBoxResult, N As Byte 

'定义一个中文标点的数组对象 

ChineseInterpunction = Array("、","。", ",", ";", ":", "?", "!", "„„", "

—", "~", "(", ")", "《", "》") 

'定义一个英文标点的数组对象 

EnglishInterpunction = Array(",",".", ", ":", "!", "„", "-", "~", "(", ")", "<", ">") '

注意这里的英文,转换为了中文、,如果希望将,转换为中文,请自行修改! 

'提示用户交互的MSGBox对话框 

msgResult = MsgBox("您想中英标点互换吗?按Y将中文标点转为英文标点,按N将英文标点

转为中文标点!", vbYesNoCancel) 

Select Case msgResult 

Case vbCancel 

Exit Sub '如果用户选择了取消按钮,则退出程序运行 

Case vbYes '如果用户选择了YES,则将中文标点转换为英文标点 

myArray1 = ChineseInterpunction 

myArray2 = EnglishInterpunction strFind = "“(*)”" 

strRep = """1""" Case vbNo '如果用户选择了NO,则将英文标点转换为中文标点 myArray1 = EnglishInterpunction myArray2 = ChineseInterpunction 

strFind = """(*)""" 

strRep = "“1”" 

End Select 

Application.ScreenUpdating = False '关闭屏幕更新 

For N = 0 To UBound(ChineseInterpunction) '从数组的下标到上标间作一个循环 

With ActiveDocument.Content.Find 

.ClearFormatting '不限定查找格式 

.MatchWildcards = False '不使用通配符 

'查找相应的英文标点,替换为对应的中文标点 

.Execute findtext:=myArray1(N), replacewith:=myArray2(N), Replace:=wdReplaceAll 

End With 

Next

With ActiveDocument.Content.Find 

.ClearFormatting '不限定查找格式 

.MatchWildcards = True '使用通配符 

.Execute findtext:=strFind, replacewith:=strRep, Replace:=wdReplaceAll 

End With 

Application.ScreenUpdating = True '恢复屏幕更新 

End Sub  

4、任意页插入页码 

Sub任意页插入页码() 

Dim p As Integer 

On Error Resume Next 

p = InputBox("请输入起始编排页码的页次") 

With Selection 

.GoTo What:=wdGoToPage, Count:=p 

.InsertBreak Type:=wdSectionBreakContinuous 

.Sections(1).Footers(1).LinkToPrevIoUs = False 

With .Sections(1).Footers(1).PageNumbers 

.RestartNumberingAtSection = True .StartingNumber = 1 

.Add PageNumberAlignment:=wdalignPageNumberCenter, FirstPage:=True 

End With 

End With 

End Sub  

5、实现图形的精确旋转 

Sub 图形旋转() 

Dim blnIsInlineshape As Boolean 

If Selection.Type = wdSelectionInlineshape Then 

blnIsInlineshape = True 

Selection.Inlineshapes(1).ConvertToShape 

End If 

Dim intTurn As Integer 

intTurn = InputBox("请输入图形要旋转的角度值" & vbCrLf & "正数表示顺时针,负数表示逆时针。", "图形旋转", 30) 

Selection.ShapeRange.IncrementRotation intTurn 

End Sub 

相关文章: word常见问题汇总 | word工具栏隐藏显示

上述就是wordvba编程代码大全,可以给你更高的使用效率,想知道更多的教程继续的关注国旅软件(jb51.cc)哦。

以上是国旅软件为你收集整理的wordvba编程代码大全全部内容。

如果觉得国旅软件网站内容还不错,欢迎将国旅软件推荐给好友。

关于《wordvba编程代码大全》相关问题的解答飘逸小编就为大家介绍到这里了。如需了解其他软件使用问题,请持续关注国旅手游网软件教程栏目。

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如果发现本站有涉嫌抄袭侵权/违法违规的内容,欢迎发送邮件至【1047436850@qq.com】举报,并提供相关证据及涉嫌侵权链接,一经查实,本站将在14个工作日内删除涉嫌侵权内容。

本文标题:【wordvba编程手册[word vba编程]】

本文链接:http://www.citshb.com/class170303.html