如何利用VB6向word模板页眉中的表格写入内容(文本框中的内容)。向正文写入知道,就是向页眉写入弄不好。

如题所述

如果我理解不错的话,你是在用vb6调用office 的COM interface来做automation的。要想改变眉页的东西似乎需要先改变视图,然后加入一个表格(如果你说的表格是table的话),然后修改table的内容,最后再跳回到main document视图。

这是我用vba录的宏,应该很容易修改成vb6的代码。我手上没有vb6,不过我估计差不多。大家一般用vb6乃至.net来做office的automation,不知道的东西都是用vba录宏然后翻译的。
================
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=2, NumColumns:= _
3, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:= _
wdAutoFitFixed
With Selection.Tables(1)
If .Style <> "Table Grid" Then
.Style = "Table Grid"
End If
.ApplyStyleHeadingRows = True
.ApplyStyleLastRow = False
.ApplyStyleFirstColumn = True
.ApplyStyleLastColumn = False
.ApplyStyleRowBands = True
.ApplyStyleColumnBands = False
End With
Selection.TypeText Text:="cell1"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="cell2"
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
--------追问

不行,写入正文中的表格了

追答

你把ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader之后的代码注视掉,看看能不能跳到header的编辑状态先。如果能跳过去,估计是table的放置点有问题。如果不能的话就得再想辙了。

温馨提示:答案为网友推荐,仅供参考
第1个回答  2011-09-10
这个问题不清楚
相似回答