十年網(wǎng)站開發(fā)經(jīng)驗 + 多家企業(yè)客戶 + 靠譜的建站團隊
量身定制 + 運營維護+專業(yè)推廣+無憂售后,網(wǎng)站問題一站解決
本篇內(nèi)容主要講解“word vba編程代碼有哪些”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實用性強。下面就讓小編來帶大家學(xué)習(xí)“word vba編程代碼有哪些”吧!
創(chuàng)新互聯(lián)公司-云計算及IDC服務(wù)提供商,涵蓋公有云、IDC機房租用、川西大數(shù)據(jù)中心、等保安全、私有云建設(shè)等企業(yè)級互聯(lián)網(wǎng)基礎(chǔ)服務(wù),咨詢電話:18980820575
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?'恢復(fù)屏幕更新?
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?
到此,相信大家對“word vba編程代碼有哪些”有了更深的了解,不妨來實際操作一番吧!這里是創(chuàng)新互聯(lián)網(wǎng)站,更多相關(guān)內(nèi)容可以進入相關(guān)頻道進行查詢,關(guān)注我們,繼續(xù)學(xué)習(xí)!