導航:首頁 > 編程語言 > 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編程手冊相關的資料

熱點內容
程序員戴手錶影響工作嗎 瀏覽:235
游戲皇後解壓視頻 瀏覽:367
c語言怎麼打開文件編譯 瀏覽:436
手機上什麼app可以設計logo 瀏覽:800
pid演算法單片機 瀏覽:375
python數據精度 瀏覽:632
管什麼小女孩App 瀏覽:192
phppdf轉換成圖片 瀏覽:468
十八講pdf 瀏覽:619
mysql導入壓縮文件 瀏覽:21
usb控制單片機 瀏覽:906
你為什麼喜歡安卓手機 瀏覽:863
阿里雲伺服器購買和使用 瀏覽:389
單片機sp1 瀏覽:282
大學生玩貓咪解壓 瀏覽:794
php附近的演算法 瀏覽:346
黑馬程序員培訓機構怎麼樣 瀏覽:36
怎麼查找伺服器ip地址 瀏覽:371
華為手機為什麼開不了定位伺服器地址 瀏覽:970
美容美發app哪裡有 瀏覽:8