导航:首页 > 编程语言 > 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编程手册相关的资料

热点内容
阿里云服务器怎么更改ip 浏览:643
pvp和普通服务器有什么区别 浏览:706
pc收银台系统源码 浏览:624
程序员老公要加班 浏览:961
51单片机控制的超声波 浏览:827
2021去水印最新源码 浏览:232
ug编程刀具号重复 浏览:960
空当接龙算法 浏览:609
可压缩流体非恒定二维流动 浏览:695
天龙八部网单没有找到技能文件夹 浏览:861
android串口程序 浏览:833
上海机器人程序员 浏览:914
两台阿里云服务器如何拷贝 浏览:170
阿里妈妈淘宝联盟需要什么app 浏览:368
什么人可以做编程员 浏览:359
网盘会员加速是在线解压嘛 浏览:109
单片机按键汇编程序 浏览:729
传播学纲要pdf第二版 浏览:385
乐友进销存有什么app 浏览:554
显示器维修pdf 浏览:618