用户登录
用户注册

分享至

vbaword插入节

  • 作者: diao大宅
  • 来源: 51数据库
  • 2020-04-21

如何用VBA修改word的节开始的分节符

录制一个宏就知道了。

1、插入分节符(下一页)Selection.InsertBreakType:=wdSectionBreakNextPage2、后面插入指定图片。路径是中间那句jpg格式的,要更改成自己的。

Selection.InlineShapes.AddPictureFileName:=_"C:\DocumentsandSettings\AllUsers.WINDOWS\Documents\MyPictures\示例图片\Bluehills.jpg"_,LinkToFile:=False,SaveWithDocument:=TrueWORD的VBA主要是Selection事件,即光标移动到某一位置(当前),然事执行某项操作,一般用录制宏可解决。

Word中如何用VBA自动实现在插入点后面插入分节符(下一页)以及

录制一个宏就知道了。

1、插入分节符(下一页)

Selection.InsertBreak Type:=wdSectionBreakNextPage

2、后面插入指定图片。路径是中间那句jpg格式的,要更改成自己的。

Selection.InlineShapes.AddPicture FileName:= _

"C:\Documents and Settings\All Users.WINDOWS\Documents\My Pictures\示例图片\Blue hills.jpg" _

, LinkToFile:=False, SaveWithDocument:=True

WORD的VBA主要是Selection事件,即光标移动到某一位置(当前),然事执行某项操作,一般用录制宏可解决。

如何用VBA代码为Word添加菜单(即命令栏)

Dim myMenuBar

Dim newMenu

Dim ctrl1

Dim s

Dim flag As String

'初始化菜单

Set myMenuBar = CommandBars.ActiveMenuBar

Set newMenu = myMenuBar.Controls.Add(Type:=msoControlPopup, _

Temporary:=True)

newMenu.Caption = "电子印章"

Set ctrl1 = newMenu.Controls.Add(Type:=msoControlButton, ID:=1)

ctrl1.Caption = "添加电子印章"

ctrl1.Style = msoButtonCaption

ctrl1.OnAction = "AddSeal"

Set ctrl1 = newMenu.Controls.Add(Type:=msoControlButton, ID:=1)

ctrl1.Caption = "验证电子印章"

ctrl1.Style = msoButtonCaption

ctrl1.OnAction = "CheckSeal"

ctrl1.Style = msoButtonCaption

Set ctrl1 = newMenu.Controls.Add(Type:=msoControlButton, ID:=1)

ctrl1.Caption = "关于"

ctrl1.OnAction = "About"

ctrl1.Style = msoButtonCaption

如何用vba给一个word表格的最后插入一行

用ActiveDocument.Tables(1).Rows.Add好像也行,不知两者的效果有没有区别。

ActiveDocument.Tables(1).Rows.Add方法总是在指定行的前面插入行。

如:

Sub Example2()

Dim myTable As Table, myLastRow As Row

Set myTable = Me.Tables(1)

Set myLastRow = myTable.Rows.Last

myTable.Rows.Add myLastRow

End Sub

而Selection对象可以在所选行的上方或者下方插入等量的行。

注意,Add方法也可以插入指定数量的行。

Sub Example3()

Dim myTable As Table, myRows As Rows

Set myTable = Me.Tables(1)

Set myRows = Me.Range(myTable.Rows(1).Range.Start, myTable.Rows(3).Range.End).Rows

myTable.Rows.Add myRows

End Sub

怎么用vba实现在word中插入excel表格

Sub AA()

Dim projectno As String, projectname As String, datereceive As Date, datecomplate As Date, functionary As String

Dim arr As Object

Dim i As Long

Dim brr

projectno = ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range.Tables(1).Cell(1, 2).Range

Dim excelobject As Object

Set excelobject = GetObject("D:\Downloads\project(word)\project.xls")

Set arr = excelobject.Sheets(1).usedrange()

brr = arr

For i = 2 To UBound(brr)

If InStr(1, projectno, brr(i, 1)) > 0 Then

projectname = brr(i, 2)

datereceive = brr(i, 3)

datecomplate = brr(i, 4)

functionary = brr(i, 5)

Exit For

End If

Next i

ActiveDocument.Tables(1).Cell(1, 2).Range = projectname

ActiveDocument.Tables(1).Cell(2, 2).Range = datereceive

ActiveDocument.Tables(1).Cell(3, 2).Range = datecomplate

ActiveDocument.Tables(1).Cell(4, 2).Range = functionary

excelobject.Close False

End Sub

转载请注明出处51数据库 » vbaword插入节

软件
前端设计
程序设计
Java相关