PDA

View Full Version : [SOLVED:] wildcard or regex pattern



Ethen5155
01-01-2020, 03:53 PM
Hi all,

well i'm looking for a wildcard or regex in vba pattern that can copy this number to a txt file (i have colored it with blue) from the whole code as i'm dealing with multiple html files and needs to get this number from

https://web.atms.a2z.com/web/login/authByToken?token=Il06qXNxARx6Dx9GUjhu5wXJnZO5fk9nDdnpPk1tJVr2001x2gP5ttJcF uJ5JQlP9&url=https%3A%2F%2Ftwe.atms.a2z.com%2Ftwe%2Ftranslation%2Fjob%2F12732403%3Fm emsourceServerUrl%3Dhttps%3A%2F%2Fatms.a2z.com

i have attached a sample file contains the codes and the output txt file i'm supposed to get

Many thanks in Advance for everyone that can help.

Cheers

gmayor
01-01-2020, 09:55 PM
Based on your example file, the following macro will extract the data. Change strPath to wherever you require the text file to be saved.


Sub Macro1()


Dim oPara As Paragraph
Dim vLink As Variant
Dim fso As Object
Dim oFile As Object
Const strPath As String = "C:\Path\Results.txt"


Set fso = CreateObject("Scripting.FileSystemObject")
Set oFile = fso.CreateTextFile(strPath)


For Each oPara In ActiveDocument.Paragraphs
If Len(oPara.Range) > 5 Then
vLink = Split(oPara.Range.Text, "%")
oFile.WriteLine Replace(vLink(UBound(vLink) - 5), "2F", "")
End If
Next oPara


oFile.Close
MsgBox "Data extracted"
lbl_Exit:
Set fso = Nothing
Set oFile = Nothing
Set oPara = Nothing
Exit Sub
End Sub