您好,登錄后才能下訂單哦!
本篇內容主要講解“word vba編程代碼有哪些”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實用性強。下面就讓小編來帶大家學習“word vba編程代碼有哪些”吧!
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??
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 vba編程代碼有哪些”有了更深的了解,不妨來實際操作一番吧!這里是億速云網站,更多相關內容可以進入相關頻道進行查詢,關注我們,繼續學習!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。