Dim oWord As word.Application
   Dim rngCurrent As word.Range
   
   Set oWord = New word.Application
   oWord.Documents.Open App.Path & "\a.doc"
   rngCurrent = oWord.ActiveDocument.Content
   txt.text = rngCurrent
小弟有两个疑问?我要实现的是读入a.doc并且赋值给txt.text.
1. oWord.Documents.Open App.Path & "\a.doc" 怎么样做才能不显示打开word的过程,我只需要读入,没必要让用户看到打开word
2. txt.text = rngCurrent总出错?这样不能得到文档内容,出错消息是,91,对象变量活WITH快变量未定义,求教

解决方案 »

  1.   

    Documents的Open方法有个Visible参数设为False即可。
      

  2.   

    可是这样还是能看到WORD啊?我想要是看不到WORD,从后台打开
      

  3.   

    急,大虾人呢?小弟只要实现把VB的内容读入并赋值给sStr
      

  4.   

    Dim wdApp As Word.Application
    Dim wdDoc As Word.Document
    Set wdApp = CreateObject("Word.application")
    wdApp.Documents.Open filename:=strSalefile, ConfirmConversions _
        :=False, ReadOnly:=True, AddToRecentFiles:=False, PasswordDocument:="", _
        PasswordTemplate:="", Revert:=False, WritePasswordDocument:="", _
        WritePasswordTemplate:="", Format:=wdOpenFormatAuto'测 试用
    'wdApp.Visible = True
    '&&&&&&&&&&&&&&&&&&&&&&&
    看不到阿看不到,读取word我记得csdn有人发过不过找不到了,我在帮你测试,可是太忙,如果没结果别着急哈,我也不知道第二个问题今天能不能有空搞定。我也是菜鸟啦
      

  5.   

    一个笨方法,把文档全选,然后取得选中的文本,进行付值咯在上面的代码后面加上wdApp.Selection.WholeStory
    MsgBox wdApp.Selection.Text就能看到你的文档的内容了
      

  6.   

    wdApp.Documents.Open filename:=strSalefile, ConfirmConversions _
        :=False, ReadOnly:=True, AddToRecentFiles:=False, PasswordDocument:="", _
        PasswordTemplate:="", Revert:=False, WritePasswordDocument:="", _
        WritePasswordTemplate:="", Format:=wdOpenFormatAuto
    中只有一个变量  strSalefile  存放的是文件的路径名,应该能看懂吧。把这个变量负值为你的文件的路径名就可以打开你的文件了
      

  7.   

    vba中的while do 循环应该怎么写?
      

  8.   

    Private Sub Command2_Click()
    Dim oWordApp As Word.Application
    Dim a As String
    '开始一个Microsoft Word实例
    Set oWordApp = CreateObject("Word.Application")
     
        With oWordApp
            oWordApp.WindowState = wdWindowStateMinimize
            oWordApp.Documents.Open App.Path & "\a.doc"
            With oWordApp
     
               a = .ActiveDocument.Content
               .Quit
            End With
            'Content = App.Path & "\a.doc"
        End With
    End Sub
    这个能读WORD内容了,但是小弟想问如何不让用户选择是"打开为只读副本"等,就是调用OPEN后会让用户选择的对话框,怎么能默认选择打开为只读副本?
      

  9.   

    啊,才看到是vba啊。我的代码是在vb中的,不过vba也可以吧,大概调整下吧while循环不是一样的语法么?do  while()
    loop
      

  10.   

    只读?副本?不晓得
    wdApp.Documents.Open filename:=strSalefile, ConfirmConversions _
        :=False, ReadOnly:=True, AddToRecentFiles:=False, PasswordDocument:="", _
        PasswordTemplate:="", Revert:=False, WritePasswordDocument:="", _
        WritePasswordTemplate:="", Format:=wdOpenFormatAuto中的readonly :=  true 不是只读么?