导航:首页 > 文件教程 > 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插入表格相关的资料

热点内容
暴风转码如何添加文件夹 浏览:515
延安整合网络营销有哪些 浏览:74
查找word打开过的文件在哪里 浏览:137
b树java代码 浏览:683
电脑文件存储 浏览:657
兰州中考征集志愿在哪个网站 浏览:215
cs文件上传下载 浏览:244
拷贝文件到根目录下重命名linux 浏览:603
api函数的头文件 浏览:249
华为怎么绑定迷你编程 浏览:215
机构怎么申请少儿编程考级 浏览:495
昆山数控编程哪里好学 浏览:459
jspcfor跳出 浏览:65
word怎么插入罗马数字i 浏览:315
哪个网站可以找到法人代表 浏览:106
苹果5s日版a1453支持什么网络 浏览:297
微信打开文件如何设置 浏览:218
漫画书app中非可视组件是什么 浏览:3
d盘文件隐藏怎么恢复 浏览:287
5s怎么设置联通4g网络 浏览:15

友情链接