为什么可以读取txt 文件的内容, 不可以读取doc 文件的内容, 要做到这一点应该怎样做?
下面的代码可以把txt 文件的内容读出, 但是若把txt 改为doc , 也可以读取doc 文件,但显示出来的是乱码. Option Explicit
Private fs As Variant
Private a As VariantPrivate Sub Command1_Click()
Dim k As String
Open (Dir1.Path + "\" + File1.FileName) For Input As 1#Line Input #1, k
MsgBox (k)
Close 1#
End SubPrivate Sub Dir1_Change()
File1.Path = Dir1.Path
File1.FileName = "*.txt"End SubPrivate Sub Drive1_Change()
Dir1.Path = Drive1.Drive
End SubPrivate Sub Form_Load()
File1.FileName = "*.txt"
end sub
下面的代码可以把txt 文件的内容读出, 但是若把txt 改为doc , 也可以读取doc 文件,但显示出来的是乱码. Option Explicit
Private fs As Variant
Private a As VariantPrivate Sub Command1_Click()
Dim k As String
Open (Dir1.Path + "\" + File1.FileName) For Input As 1#Line Input #1, k
MsgBox (k)
Close 1#
End SubPrivate Sub Dir1_Change()
File1.Path = Dir1.Path
File1.FileName = "*.txt"End SubPrivate Sub Drive1_Change()
Dir1.Path = Drive1.Drive
End SubPrivate Sub Form_Load()
File1.FileName = "*.txt"
end sub
请问除了WebBrowser还有什么控件 可以读取doc 文档
你可以用二进制方式打开他
然后,可以用判断 ASCII码的值,过滤掉那些乱码
Set ex = CreateObject("excel.application")
Set exwbook = ex.workbooks.Open("" & App.Path & "\你的EXCEL文档")
这样可以打开一个EXCEL文档 。方法和WORD 一样的。
只是在后台打开,全文贴来你的文本档里即可
出现不能创建对象错误.
调试时发现下面的东西不能调试通过
Set appXOffice = CreateObject("XOffice.Application")
open 方法只提供了简单的文件访问功能
要访问doc用XOffice.Application吧
Dim appWord As Word.Application
Set appWord = CreateObject("Word.Application")
Private Sub Command1_Click()
Set wrdApp = New Word.Application '写word文档
With wrdApp
'Show Word
.Visible = True
'Create New Document
.Documents.Add
'Add text to the document
.ActiveDocument.Content.Text = "Hi"
.ActiveDocument.Content.Text = "This is a test example"
End With
End SubPrivate Sub Command2_Click()
Dim sFileName, sContent, sPartContent As String '打开word文档
Dim wrdApp As Object
Dim k As String
CommonDialog1.ShowOpen
If Err <> 0 Then Exit Sub
sFileName = CommonDialog1.FileName
If sFileName = "" Then Exit Sub
Set wrdApp = CreateObject("Word.Application")
wrdApp.Visible = True
wrdApp.Documents.Open (sFileName)
sContent = wrdApp.ActiveDocument.Content
End Sub