LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 24
Default combining multiple find/replace subs

On Apr 22, 3:53*pm, "Rick Rothstein \(MVP - VB\)"
wrote:
Below my signature is a subroutine which proved to be quite
speedy from a past posting of mine, modified for what I think
your conditions are. Give it a try and let me know how it works
out for you.


Actually Rick, it works perfectly fine! *I was confused with the
With (SheetName) - I was putting the actual name of the sheet
in there forgetting it was already dimensioned as a variable.
Thanks so much!


You said your original code took nearly an hour... out of curiosity, how
long did the routine I posted take?

Rick


It was originally about exactly an hour, and now its about 15
minutes. That's a pretty substantial amount of processing time!

Hey would you mind looking at something else for me? I have code that
finds all .txt files within a folder and its subfolders. It finds
these .txt files, then searches through them for any reference of
"href" (the .txt files are web site source code). When it finds an
"href" is copies the entire line and puts into Excel. I don't need
all the stuff in the actual line so I have code to take what I need.
Essentially I am searching for all 3rd party sites. I am able to get
the URL of the page the 3rd party link is on in column A, and the URL
of the 3rd party link into column B. I am trying to get 2 more
things, the Title of the page, and the name of the 3rd party link on
the page. When I run the code, I get no errors but the columns don't
populate. Here is the code that I have, any suggestions would be
great! Thanks!

Mark

Sub CheckTextFilesForHREFs()

MsgBox "Press OK to begin report"
Dim WholeLine As String
Dim myPath As String
Dim workfile As String
Dim myR As Long

myPath = "C:\Exelon\"
workfile = Dir(myPath & "*.html")
'sLine = WholeLine

Set fs = Application.FileSearch
With fs
.LookIn = "C:\Exelon"
.Filename = ".html"
.SearchSubFolders = True
'.FileType = mosFileTypeAllFiles
If .Execute(SortBy:=msoSortByFileName, _
SortOrder:=msoSortOrderAscending) 0 Then
MsgBox "There were " & .FoundFiles.Count & _
" file(s) found."
For i = 1 To .FoundFiles.Count
ParseURL .FoundFiles(i)
ParseTitle .FoundFiles(i) 'these are the ones it won't
populate
ParseLink .FoundFiles(i) 'these are the ones it won't
populate
Next i

Else
MsgBox "There were no files found."
End If
End With

Sub ParseURL(strFile As String) 'THIS ONE WORKS FINE
Dim strTxt As String, lngTxt As Long, i As Long, oMatches
Dim ws As Worksheet, j As Long, k As Long, m As Long, oMatches2
Dim reg, oMatches3, reg2
i = FreeFile
'strFile = "c:\Users\Richard\Documents\Htmltest.html"
lngTxt = FileLen(strFile)
strTxt = Space(lngTxt)
Open strFile For Binary Access Read As #i
Get #i, , strTxt
Close #i
Debug.Print strTxt
With CreateObject("vbscript.regexp")
.Global = True
.ignorecase = True
.Pattern = vbCrLf & ".*?href.*?(?=" & vbCrLf & ")"
If .test(strTxt) Then
Set oMatches = .Execute(strTxt)
For i = 0 To oMatches.Count - 1
Set reg = CreateObject("vbscript.regexp")
With reg
.Global = True
.ignorecase = True
.Pattern = "href=\""(.*?)\"""
k = Cells(Rows.Count, 1).End(xlUp).Offset(1).Row
Cells(k, 1).Value = strFile
If .test(oMatches(i)) Then
Set oMatches2 = .Execute(oMatches(i))
For j = 0 To oMatches2.Count - 1
Cells(k, j + 2) = .Replace(oMatches2(j),
"$1")
Next j
End If
End With
Next i
End If
End With
End Sub

Sub ParseLink(strFile As String)
Dim strTxt As String, lngTxt As Long, i As Long, oMatches
Dim ws As Worksheet, j As Long, k As Long, m As Long, oMatches2
Dim reg, oMatches3, reg2
i = FreeFile
'strFile = "c:\Users\Richard\Documents\Htmltest.html"
lngTxt = FileLen(strFile)
strTxt = Space(lngTxt)
Open strFile For Binary Access Read As #i
Get #i, , strTxt
Close #i
Debug.Print strTxt
With CreateObject("vbscript.regexp")
.Global = True
.ignorecase = True
.Pattern = vbCrLf & ".*?href.*?(?=" & vbCrLf & ")"
If .test(strTxt) Then
Set oMatches = .Execute(strTxt)
For i = 0 To oMatches.Count - 1
Set reg = CreateObject("vbscript.regexp")
With reg
.Global = True
.ignorecase = True
.Pattern = "<A \""(.*?)\""</A"
<------------------------------not sure if syntax is right here
k = Cells(Rows.Count, 1).End(xlUp).Offset(1).Row
Cells(k, 1).Value = strFile
If .test(oMatches(i)) Then
Set oMatches2 = .Execute(oMatches(i))
For j = 0 To oMatches2.Count - 1
Cells(k, j + 4) = .Replace(oMatches2(j),
"$1")
Next j
End If
End With
Next i
End If
End With
End Sub
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Multiple Criteria Find & Replace Alfred Excel Worksheet Functions 3 October 21st 09 07:13 PM
multiple find and replace Andre Excel Worksheet Functions 1 May 26th 09 02:31 PM
Multiple Find and Replace in one function [email protected] Excel Worksheet Functions 4 September 11th 06 03:16 AM
Combining two Subs Petitboeuf Excel Discussion (Misc queries) 6 April 27th 06 03:42 PM
Combining find with clearcontents on multiple columns RussB Excel Programming 1 January 13th 06 11:20 PM


All times are GMT +1. The time now is 06:39 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"