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?'無偶數(shù)頁'?
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??
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?
’定義一個中文標點的數(shù)組對象?
ChineseInterpunction?=?Array('、','。',?',',?';',?':',?'?',?'!',?'??',?'
—',?'~',?'(',?')',?'《',?'》')?
’定義一個英文標點的數(shù)組對象?
EnglishInterpunction?=?Array(',','.',?',',?';',?':',?'?',?'!',?'?',?'-',?'~',?'(',?')',?'<',?'>')?’
注意這里的英文,轉(zhuǎn)換為了中文、,如果希望將,轉(zhuǎn)換為中文,請自行修改!?
’提示用戶交互的MSGBOX對話框?
msgResult?=?MsgBox('您想中英標點互換嗎?按Y將中文標點轉(zhuǎn)為英文標點,按N將英文標點
轉(zhuǎn)為中文標點!',?vbYesNoCancel)?
Select?Case?msgResult?
Case?vbCancel?
Exit?Sub?’如果用戶選擇了取消按鈕,則退出程序運行?
Case?vbYes?’如果用戶選擇了YES,則將中文標點轉(zhuǎn)換為英文標點?
myArray1?=?ChineseInterpunction?
myArray2?=?EnglishInterpunction?strFind?=?'“(*)”'?
strRep?=?'''1'''?Case?vbNo?’如果用戶選擇了NO,則將英文標點轉(zhuǎn)換為中文標點?myArray1?=?EnglishInterpunction?myArray2?=?ChineseInterpunction?
strFind?=?'''(*)'''?
strRep?=?'“1”'?
End?Select?
Application.ScreenUpdating?=?False?’關(guān)閉屏幕更新?
For?N?=?0?To?UBound(ChineseInterpunction)?’從數(shù)組的下標到上標間作一個循環(huán)?
With?ActiveDocument.Content.Find?
.ClearFormatting?’不限定查找格式?
.MatchWildcards?=?False?’不使用通配符?
’查找相應(yīng)的英文標點,替換為對應(yīng)的中文標點?
.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、實現(xiàn)圖形的精確旋轉(zhuǎn)?
Sub?圖形旋轉(zhuǎn)()?
Dim?blnIsInlineShape?As?Boolean?
If?Selection.Type?=?wdSelectionInlineShape?Then?
blnIsInlineShape?=?True?
Selection.InlineShapes(1).ConvertToShape?
End?If?
Dim?intTurn?As?Integer?
intTurn?=?InputBox('請輸入圖形要旋轉(zhuǎn)的角度值'?&?vbCrLf?&?'正數(shù)表示順時針,負數(shù)表示逆時針。',?'圖形旋轉(zhuǎn)',?30)?
Selection.ShapeRange.IncrementRotation?intTurn?
End?Sub?
相關(guān)文章: word常見問題匯總 |
以上就是wordvba編程代碼大全的全部內(nèi)容,望能這篇wordvba編程代碼大全可以幫助您解決問題,能夠解決大家的實際問題是好吧啦網(wǎng)一直努力的方向和目標。
相關(guān)文章: