Private Sub Command2_Click() Dim oword As Word.Application Dim aa As Word.Document
Set oword = CreateObject("Word.Application") oword.Documents.Open "i:\test.doc"
Set aa = oword.ActiveDocument
aa.Range.Copy MsgBox Clipboard.GetText aa.Close Set aa = Nothing Set oword = Nothing End Sub
用RichTextBox显示Word里的内容,更丰富多彩,具体方法如下: Private Sub Openfile(byval strWordDoc as String) dim m_strTmpRtfFile as String Dim objWord As Object Dim objWordDocument As Word.Document Const CLASSOBJECT = "Word.Application" m_strTmpRtfFile = app.path & "\tmp.rtf" If (objWord Is Nothing) Then Set objWord = CreateObject(CLASSOBJECT) End If Set objWordDocument = objWord.Documents.Open(FileName:=strWordDoc) objWord.Visible = False objWordDocument.SaveAs m_strTmpRtfFile, wdFormatRTF '另存为RTF格式
Set objWordDocument = Nothing objWord.Quit SaveChanges:=wdDoNotSaveChanges '退出Word Set objWord = Nothing If Dir(m_strTmpRtfFile) <> "" Then RichTextBox1.LoadFile m_strTmpRtfFile, 0 Kill m_strTmpRtfFile End If End sub
Dim oword As Word.Application
Dim aa As Word.Document
Set oword = CreateObject("Word.Application")
oword.Documents.Open "i:\test.doc"
Set aa = oword.ActiveDocument
aa.Range.Copy
MsgBox Clipboard.GetText
aa.Close
Set aa = Nothing
Set oword = Nothing
End Sub
Private Sub Openfile(byval strWordDoc as String)
dim m_strTmpRtfFile as String
Dim objWord As Object
Dim objWordDocument As Word.Document
Const CLASSOBJECT = "Word.Application"
m_strTmpRtfFile = app.path & "\tmp.rtf"
If (objWord Is Nothing) Then
Set objWord = CreateObject(CLASSOBJECT)
End If
Set objWordDocument = objWord.Documents.Open(FileName:=strWordDoc)
objWord.Visible = False
objWordDocument.SaveAs m_strTmpRtfFile, wdFormatRTF '另存为RTF格式
Set objWordDocument = Nothing
objWord.Quit SaveChanges:=wdDoNotSaveChanges '退出Word
Set objWord = Nothing
If Dir(m_strTmpRtfFile) <> "" Then
RichTextBox1.LoadFile m_strTmpRtfFile, 0
Kill m_strTmpRtfFile
End If
End sub
到了RichText丢少点