你是想在WORD的表格中插值吗?
解决方案 »
- 求助VB中DataGrid控件与SQL Server数据库连接问题
- 求助,我现在需要做直接从COM口打印,打印机是TM U220B,用VB.60 VB.net C#都行,请问有高手做过这方面的没有!!谢谢
- 高分相求解决用vbscript 执行cmd命令的方法
- VB中字符串数组排序
- 新建一个excel的方法。
- 在VB中在打开文件之前如何判断该文件是否已经打开了
- 谁有XP样式的COMBOBOX控件,最好有源码!!!!!!!!!!!!!!!!!!!!!
- 我这么做为什么老出错?(内附代码)
- 多线程,真的没有人会吗?
- 发疯了,搞了半天没解决,关于VB刷新WebBrowser问题
- 请问哪里可以下载SourceSafe?
- 请问VB里如何实现菜单中的“最近使用过的文件”。(很多软件都有的功能)
编写前提,引用(references):Microsoft word 9.0 object libray
Visual basic for application (也许不需要) Dim Long_x As Integer
Dim Str_x As String
Dim appWord As Word.Application
Dim wdocObj As Word.Document
Dim Str_1 As String
Dim Str_T1_1 As String
'****** Define StringStr_1 = "Ok!!!!!" Str_T1_1 = "Ok!!!!!"
'******* Open Word
On Error GoTo notloaded
Set appWord = GetObject(, "Word.Application.8")
notloaded:
If Err.Number = 429 Then
Set appWord = CreateObject("Word.Application.8")
interror = Err.Number
End If
appWord.Visible = True
appWord.Activate
Set wdocObj = appWord.Documents.Open("c:\PIME2001\Sollicitud.DOC") '指定DOC路径.
'******* Change Data
' --- Str_1 普通文档插值
Str_x = Str_1
With appWord.Selection
.Goto What:=wdGoToPage, Which:=wdGoToFirst '移动--页
.Goto What:=wdGoToLine, Which:=wdGoToRelative, Count:=4 '移动--行
.MoveRight , 14 '移动--格
.Font.Name = "Times New Roman"
.Font.Color = wdColorBlue
.Font.Size = 11
.Font.Italic = True
Long_x = Len(Str_x)
.Delete , Long_x
.TypeText " " & Str_x & " "
End With
' --- Str_T1_1 '在表格里插值
Str_x = Str_T1_1
With appWord.Selection
.Goto What:=wdGoToPage, Which:=wdGoToFirst '2
.Goto What:=wdGoToLine, Which:=wdGoToRelative, Count:=25
.Tables(1).Cell(1, 2).Range.Font.Color = wdColorBlue
.Tables(1).Cell(1, 2).Range.Font.Size = 11
.Tables(1).Cell(1, 2).Range.Font.Name = "Times New Roman"
.Tables(1).Cell(1, 2).Range.Font.Italic = True
.Tables(1).Cell(1, 2).Range.Text = Str_x
End With
该段代码可以插值,但不能完全保证DOC文档版面的一致,原因是:
LEN()计算的只是字符个数,但不是字符显示长度.希望这段代码可以帮到你.
而且如果谁可以解决显示长度的问题,也请告知.
我的EMAIL: [email protected]