导航:首页 > 文件教程 > vbaword插入表格

vbaword插入表格

发布时间:2024-07-28 18:26:30

1. 如何用 word VBA 在任一选定区域插入1×1表格,既用表框起来,另有它用。谢谢

这种事情,用录制宏就可以了

录制之前,先选定一个区域

开始录制
把选定区域内容剪切,
在当前位置插入一个表格
把剪切内容粘贴进表格
结束录制

我的 Word 2007 ,录制的结果是这样的

Sub 宏1()
Selection.Cut
ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=1, NumColumns:= _
1, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:= _
wdAutoFitFixed
With Selection.Tables(1)
If .Style <> "网格型" Then
.Style = "网格型"
End If
.ApplyStyleHeadingRows = True
.ApplyStyleLastRow = False
.ApplyStyleFirstColumn = True
.ApplyStyleLastColumn = False
.ApplyStyleRowBands = True
.ApplyStyleColumnBands = False
End With
Selection.PasteAndFormat (wdPasteDefault)
End Sub

2. 在Excel中,通过VBA往word表格里写数据时,如何根据内容增加或者减少word表格列数

可以通过word的table对象对word表格进行操作。下面的代码在Excel的Vba中运行,运行前先添加Microsoft Word XX.0 Object Library的引用,其中XX.0根据你安装的Office 版本不同而不同,一般来试Office Word 2003 是11.0,Office Word 2013 是15.0 。

SubtoWord()
DimwordAppAsNewWord.Application
wordApp.Visible=True
DimwordDocAsWord.Document
DimwordTableAsWord.Table

SetwordDoc=wordApp.Documents.Add'新建一个文档

SetwordTable=wordDoc.Tables.Add(wordDoc.Range(),1,1,wdWord9TableBehavior,wdAutoFitWindow)'文档中插入一个表格
DimrAsLong,cAsLong
Forr=1ToActiveSheet.UsedRange.Rows.Count
Ifr>wordTable.Rows.CountThen
wordTable.Rows.Add'表格插入行
EndIf
Forc=1ToActiveSheet.UsedRange.Columns.Count
Ifc>wordTable.Columns.CountThen
wordTable.Columns.Add'表格插入列
wordTable.Columns.AutoFit
EndIf
wordTable.Cell(r,c).Range.Text=Cells(r,c)
Nextc
Nextr
wordTable.
EndSub

3. 如何用vba代码向word文档中插入表格

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

阅读全文

与vbaword插入表格相关的资料

热点内容
ug100如何编程画线 浏览:870
文件夹999找不到 浏览:145
win1014393最新版本号 浏览:100
java基本类型大小 浏览:516
word2007不能插入页码 浏览:968
vb读取文件并判断 浏览:6
php图片和程序分离 浏览:412
安卓面试非计算机专业 浏览:228
u盘的光盘文件怎么驱动 浏览:34
如何锁定c盘不下文件 浏览:359
浙江推广网站建设怎么做 浏览:478
word文件只有10页怎么增加 浏览:921
itunes下载的系统在哪个文件夹 浏览:605
个性化linux全名要求 浏览:40
数据表格制图小红点如何去掉 浏览:244
查询iphone版本信息失败怎么办 浏览:978
电脑版微信下载的文件保存在哪里 浏览:367
linuxsocket转发 浏览:32
迷你兔数据恢复软件可免费恢复多少 浏览:139
编程器怎么烧录两个不同的程序 浏览:214

友情链接