|
在excel中用vba代码添加word表格,写了一些代码,怎样都实现不了,但这些代码放在word中就能实现.
不知为何,请各位高手帮忙看看,具体的情况见附件.谢谢
Private Sub CommandButton1_Click()
On Error Resume Next
Dim WordAPP As Object, myWord As Object
Dim Fullname As String
Fullname = ThisWorkbook.Path & "\新表格.doc"
Set WordAPP = CreateObject("Word.Application")
Set myWord = WordAPP.documents.Open(ThisWorkbook.Path & "\表格.doc")
WordAPP.Visible = False
'============================追加表格==================================
myWord.Activate
myWord.tables(2).Rows.Last.Select '从最后一行开始添加表格
Selection.InsertRowsBelow 10
'============================追加表格==================================
With myWord
With .tables(1)
.Cell(1, 2).Range = Date
End With
End With
myWord.SaveAs Filename:=Fullname
myWord.Close
Set myWord = Nothing
Set WordAPP = Nothing
End Sub |
|