VB如何读取word中表格第一列、第二列内容?
VB如何读取word中表格第一列、第二列内容?回复 楼主 xingming022
程序代码:
Option Explicit Dim str1 As String Dim str2 As String Private Sub Command1_Click() Dim myword As Object, mydocument As Object, mytable As Object Set myword = CreateObject("Word.Application") '创建word对象 myword.Visible = True Set mydocument = myword.Documents.Open(App.Path & "\123.docx") Dim i As Byte Dim j As Byte For i = 1 To mydocument.Tables.Count Set mytable = mydocument.Tables(i) For j = 1 To mytable.Rows.Count str1 = mytable.Cell(j, 1).Range str1 = Left(str1, Len(str1) - 2) Print str1 str2 = mytable.Cell(j, 2).Range str2 = Left(str2, Len(str2) - 2) Print str2 Next Next End Sub
窗体添加一个命令按钮,AutoRedraw属性为True