好的, 我一直在編寫代碼來自動執行任務。我有一個300字的文檔,每個文檔都有一個標識號,一個標題和一個網站。我想通過標識符搜索文件,分別將標題和網站分別放入excel表格。標識符已經在excel中列出,我希望它們與適當的信息匹配。搜索Word文檔並在Excel中列出值
我知道它真的,真的凌亂 -
Public Sub ParseDoc()
Dim list As Workbook
Dim doc As Document
Set doc = "C:\network\path\importantlist.doc"
Dim paras As Paragraphs
Set paras = doc.Paragraphs
Dim para As Paragraph
Dim sents As Sentences
Dim sent As Range
Set list = ActiveSheet
Dim i As Integer
Dim mystring As String
Dim length As Integer
Dim space As String
Dim dot As String
Dim space1 As String
Dim space2 As String
Dim XYZ As Range
dot = "."
space = " "
i = 1
While i < 300 'This loops for the duration of the identifier list in excel
mystring = Cells(i, 1) ' this pulls the unique identifier from the cell
For Each para In paras
Set sents = para.Range.Sentences ' this searches the document by paragraphs to sentences
For Each sent In sents
If InStr(1, sent, mystring) <> 0 Then 'If a the identifier is found
space1 = InStr(1, sent, space, vbTextCompare) 'measure the length to the first blank space (this indicates the title is about to begin)
space2 = InStr(1, sent, dot, vbTextCompare) ' This dot is the ".doc" and indicates the title has concluded, I want the text between these two characters
Set XYZ =
Start:= space1.range.start
End:= space2.range.start
'Here is where I am stuck, I have never used range or selection before and after looking around, I still feel very much at a loss on how to proceed forward...
Next
Next
End Sub
你可以發佈一個從文檔中模擬幾行文字? –
A203 Paralegal.doc(http:// example/ F404 CAD Systems Manager.doc(http:// example/ – Mustafaar
)這些都不是有效的鏈接 –