我有一個單詞文檔,塞滿了遍佈整個文檔的代碼和URL。如何將URL文檔從word文檔複製到其他文檔?
我一直在試圖找出如何在這個word文檔中提取的所有網址並將它們粘貼到另一個文檔上?
的URL都與https://subdomain.domain.com開始在同一網站..
問題..我會需要它通常爲.jpg
我已經試着用搜索引擎,但所有結束完整的URL鏈接我發現解決方案可以提取超鏈接的URL。無法找到我的情況的解決方案,所以我希望你們可以幫忙!
我有一個單詞文檔,塞滿了遍佈整個文檔的代碼和URL。如何將URL文檔從word文檔複製到其他文檔?
我一直在試圖找出如何在這個word文檔中提取的所有網址並將它們粘貼到另一個文檔上?
的URL都與https://subdomain.domain.com開始在同一網站..
問題..我會需要它通常爲.jpg
我已經試着用搜索引擎,但所有結束完整的URL鏈接我發現解決方案可以提取超鏈接的URL。無法找到我的情況的解決方案,所以我希望你們可以幫忙!
這將解析文檔,並發現所有的URL對你的輸出數組新Document
:
Option Explicit
Sub FindLinks()
Dim p As Paragraph
Dim vSplit As Variant
Dim nIndex As Integer
Dim sURLs() As String
ReDim sURLs(0)
' find each URL and add it to an array
For Each p In ActiveDocument.Paragraphs
vSplit = Split(p.Range, " ")
For nIndex = 0 To UBound(vSplit)
If InStr(vSplit(nIndex), "https://stackoverflow.com") > 0 Then
ReDim Preserve sURLs(UBound(sURLs) + 1)
sURLs(UBound(sURLs)) = Replace(vSplit(nIndex), "src=", "")
End If
Next
Next
' create a new document and output the array
Dim sURL As Variant
Documents.Add
For Each sURL In sURLs
Selection.TypeText sURL
Selection.TypeParagraph
Next
End Sub
我編輯的代碼,以將結果發送到C:\ TEMP \ my_links.txt。您可以編輯代碼來更改目的地。
Public Sub GetUrls()
Dim r As Range
Dim outfile As String
outfile = "C:\temp\my_links.txt"
Open outfile For Output As #1
Set r = ActiveDocument.Range
r.Select
With Selection.Find
.ClearFormatting
.Text = "https://subdomain.domain.com/*.jpg"
.Forward = True
.Wrap = wdFindStop
.MatchWildcards = True
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
End With
Do While Selection.Find.Execute
Write #1, Selection.Text
Loop
Close #1
End Sub
當我在一個測試文件運行它,我得到這個在輸出文件:
"https://subdomain.domain.com/res1/joe.jpg"
"https://subdomain.domain.com/res2/cat.jpg"
希望有所幫助。
請標記答案 – AndriuZ