Dim wrdApp As Word.Application
Dim wrdDoc As Word.Document
Dim tString As String, tRange As Word.Range
Dim p As Long
Dim mFile$
Application.ScreenUpdating = False
mFile = "D:\temp\r75test.rtf"
Set wrdApp = CreateObject("Word.Application")
Set wrdDoc = wrdApp.Documents.Open(mFile, ReadOnly:=True)
With wrdDoc
For p = 1 To .Paragraphs.Count
Set tRange = .Range(Start:=.Paragraphs(p).Range.Start, _
End:=.Paragraphs(p).Range.End)
tString = tRange.Text
Debug.Print tString '讀取之後其定位點的位置己不存在了
Next p
.Close ' close the document
End With
wrdApp.Quit ' close the Word application
Set wrdDoc = Nothing
Set wrdApp = Nothing
End Sub
謝謝各位大大
[attach]11459[/attach]作者: GBKEE 時間: 2012-6-23 09:58
回復 1#dechiuan999
我 WORD 的VBA 不太熟, 試試看複製到Excel 在去處理
Sub 巨集2()
Application.ActiveDocument.Range.Copy
Word_vba
End Sub
Sub Word_vba()
Dim xlWkApp As Object, xlWk As Object
Set xlWkApp = CreateObject("excel.application")
Application.DisplayAlerts = False '關閉系統的詢問視窗
With xlWkApp
.Visible = True
Set xlWk = .workbooks.Open(FileName:="d:\試算表\Book3.xls", Password:="1234", IgnoreReadOnlyRecommended:=False)