关于VB内用VBA制表后,表格的行高不一致的问题
为什么在按了第一次command后,显示出正常的行高,再第二次按command后,行高变窄了呢,不明原因,请各位帮助,谢谢
Option Explicit
Private Sub Command2_Click()
Dim wdAp As Object '查验有否活动文档
On Error Resume Next
Set wdAp = GetObject(, "Word.Application")
If Err.Number = 0 Then
MsgBox "有WORD文档已启动,请先退出后再运行本程序!", vbInformation
Exit Sub
End If
wdAp.Quit
Set wdAp = Nothing
Dim myDoc, WordApp As Object
Set WordApp = CreateObject("Word.Application")
Set myDoc = WordApp.Documents.Add()
WordApp.Visible = False ' True
WordApp.Selection.TypeParagraph '回车
WordApp.ActiveDocument.Tables.Add Range:=WordApp.Selection.Range, NumRows:=7, NumColumns:=6, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:=wdAutoFitFixed
WordApp.ActiveDocument.Tables(1).Select '选中整个表格
WordApp.Selection.Rows.HeightRule = wdRowHeightExactly '设置行高
WordApp.Selection.Rows.Height = CentimetersToPoints(1.03) '设置行高
WordApp.Selection.Cells.VerticalAlignment = wdCellAlignVerticalCenter '垂直居中
WordApp.ActiveDocument.Tables(1).Rows.Alignment = wdAlignParagraphCenter '表格页面居中
WordApp.ActiveDocument.SaveAs App.Path & "\1.doc"
WordApp.Quit '退出
Set WordApp = Nothing
End Sub
[解决办法]
这样改一下就可以,原因我也说不清
WordApp.Selection.Rows.Height =WordApp.CentimetersToPoints(1.03) '设置行高