你是想在WORD的表格中插值吗?

解决方案 »

  1.   

    好像要用range对象插值,不管在那个cell。
      

  2.   

    是的,我想在vb中调用WORD,并插值以实现套打!
      

  3.   

    以下是在VB中实现打开DOC文档,并自动插值的代码.
    编写前提,引用(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]