如何在VB中讀取一個WORD文件中的某一單詞下面的N行前面的n個字符,比如:
      讀取WORD文件如下:
       MICROSOFT:
       中華人民共和國                                    ab中華人民共和國
       中共中央
       中國國民黨   
      現讀取microsoft:下而的3行前輩30個字符也就是要得到如下結果并存入表中
       中華人民共和國
       中共中央
       中國國民黨                 
或者誰告訴以下的代碼在VB中如何寫啊
Dim txt(3)
For i = 1 To 3
  Selection.GoTo What:=wdGoToLine, Which:=wdGoToNext, Count:=1, Name:=""  '下一行
  Selection.Find.ClearFormatting
  Selection.MoveRight Unit:=wdCharacter, Count:=30, Extend:=wdExtend  '选30个字符
  txt(i) = Selection.Text       '获得值
Next    循环3次
比如 Selection.goto  what:=wdgotoline這在VB中怎樣寫啊先謝謝各位急啊

解决方案 »

  1.   

    在VB中写是一样的,只不过要先定义object对象及定义常数。如
    const wdgotoline=.....,具体可以在word的VB编辑器中打开对象浏览器搜索。
    或运行:msgbox wdgotoline,,wdgotonext获得这两个值。
    Set obj = CreateObject(, "word.application")
    obj.open Filename:="*.doc"             '你的文件名
    Set win = obj.activewindow
    Set selection = win.Selection
    上次我给你写过,怎么还没搞定?
      

  2.   

    wdgotoline,wdgotonext是常量嗎?
    Selection.GoTo What:=wdGoToLine, Which:=wdGoToNext, Count:=1, Name:=""  
    上面的WHAT,WHICH也不是VB中的保留字,是不是也要用呢能不能幫我寫一個VB的程式(不是VBA)
    有勞了
      

  3.   

    语法是一样的,只不过要把常量声明一下。
    注意不是what=,是what:=
      

  4.   

    Private Sub Command1_Click()
    Dim obj As Object
    Dim od As Object
    Dim win As Object
    Dim sel As Object
    Dim i As Integer
    Set obj = CreateObject("word.application")
    Set od = obj.documents.open("c:\abc.doc")
    Set win = obj.activewindow
    Set sel = win.Selection
    Dim txt(3)
    For i = 1 To 3
      sel.GoTo What:=3, Which:=2, Count:=1, Name:=""
      sel.Find.ClearFormatting
      sel.MoveRight Unit:=1, Count:=30, Extend:=1
      txt(i) = sel.Text
    Next
    Label1.Caption = txt(1) + txt(2) + txt(3)
    obj.Quit
    Set obj = Nothing
    Set win = Nothing
    Set sel = NothingEnd Sub
    以上是我的VB代碼成功了  是不過是放在LABEL1中呵呵 對數據庫我就比較內行了  
    多謝你的指點,只不過改動了一行
    Set od = obj.documents.open("c:\abc.doc")
    謝謝(一會結貼, 為了讓你看到我的感謝, 故不及時結)