導航:首頁 > 編程語言 > wordvba編程手冊

wordvba編程手冊

發布時間:2022-12-15 03:33:52

① 使用VBA編程實現word公式編輯代碼

sub 1722187970()
dim m,n

m=inputbox("請輸入m的值")

n=inputbox("請輸入n的值")
msgbox "m+n的結果為" & m+n

end sub

② word如何用vba編程將重復同一內容替換為不同內容

Sub 替換()
On Error GoTo xxx:
Dim Rng As Range, n&, arr, a$
a = ActiveDocument.Content.Text
Set Rng = ActiveDocument.Content
With Rng.Find
.ClearFormatting
.Replacement.ClearFormatting
arr = Array("白日依山盡", "黃河入海流", "欲窮千里目", "更上一層樓")
Do While .Execute(findtext:="白日依山盡")
Rng = arr(n)
Rng.SetRange Rng.End, ActiveDocument.Content.End
n = n + 1
Loop
End With
GoTo yyy:
xxx:
MsgBox "文檔中詞條「白日依山盡」數目超出4個!"
yyy:
MsgBox "轉換完成!"
End Sub

③ 如何在Word中打開VBA編程窗口

一、編製程序

1.啟動Word,連續點擊「工具」,「宏」,「錄制新宏...」,在彈出的對話框中填寫宏名(此例為「作文稿紙」),選擇宏要保存的位置(可以保存在模板中,也可以保存在當前文檔中),如圖1所示。

6.雙擊命令按鈕CommandButton1,錄入以下代碼:

Private Sub CommandButton1_Click()
Dim n As Integer '定義一個變數為整數型
n = 1
ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=Val(TextBox1.Text) * 2 + 1, NumColumns _
:=Val(TextBox2.Text), DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:=wdAutoFitFixed
Selection.EndKey Unit:=wdRow, Extend:=True
Selection.Cells.Borders(wdBorderVertical).LineStyle = wdLineStyleNone
Selection.Tables(1).Rows.HeightRule = wdRowHeightExactly
'設定表格行高為固定值
Selection.Tables(1).Rows.Height = CentimetersToPoints(Val(TextBox3.Text))
'設置表格行高為設置值,作為行間距
Selection.Tables(1).Rows(1).Height = CentimetersToPoints(Val(TextBox4.Text))
'設置第一行行高為設置值
Do While n < Val(TextBox1.Text) + 1
Selection.EndKey Unit:=wdLine
Selection.MoveRight Unit:=wdCharacter, Count:=2
'將插入點移至下一行
Selection.Tables(1).Rows(2 * n).Height = Selection.Tables(1).Columns(1).PreferredWidth
'設行高等於列寬
Selection.EndKey Unit:=wdRow, Extend:=True
Selection.EndKey Unit:=wdLine
Selection.MoveRight Unit:=wdCharacter, Count:=2
'將插入點移至下一行
Selection.EndKey Unit:=wdRow, Extend:=True
Selection.Cells.Borders(wdBorderVertical).LineStyle = wdLineStyleNone
'去除此行的內部框線,只余邊框
n = n + 1
Loop
Selection.Tables(1).Rows(Val(TextBox1.Text) * 2 + 1).Height = CentimetersToPoints(Val(TextBox4.Text))
'設置末行高為設置值
Selection.EndKey Unit:=wdRow, Extend:=True
Selection.Cells.Borders(wdBorderVertical).LineStyle = wdLineStyleNone
Selection.Tables(1).Rows.Alignment = wdAlignRowCenter
'表格居中
With Selection.Tables(1)
.Borders(wdBorderLeft).LineWidth = wdLineWidth150pt
.Borders(wdBorderRight).LineWidth = wdLineWidth150pt
.Borders(wdBorderTop).LineWidth = wdLineWidth150pt
.Borders(wdBorderBottom).LineWidth = wdLineWidth150pt
'設定表格邊框為粗線
End With
Selection.EndKey Unit:=wdLine
Unload Me
End Sub

閱讀全文

與wordvba編程手冊相關的資料

熱點內容
dvd光碟存儲漢子演算法 瀏覽:758
蘋果郵件無法連接伺服器地址 瀏覽:963
phpffmpeg轉碼 瀏覽:672
長沙好玩的解壓項目 瀏覽:145
專屬學情分析報告是什麼app 瀏覽:564
php工程部署 瀏覽:833
android全屏透明 瀏覽:737
阿里雲伺服器已開通怎麼辦 瀏覽:803
光遇為什麼登錄時伺服器已滿 瀏覽:302
PDF分析 瀏覽:486
h3c光纖全工半全工設置命令 瀏覽:143
公司法pdf下載 瀏覽:383
linuxmarkdown 瀏覽:350
華為手機怎麼多選文件夾 瀏覽:683
如何取消命令方塊指令 瀏覽:350
風翼app為什麼進不去了 瀏覽:779
im4java壓縮圖片 瀏覽:362
數據查詢網站源碼 瀏覽:151
伊克塞爾文檔怎麼進行加密 瀏覽:893
app轉賬是什麼 瀏覽:163