Probably a bit of a tough one to describe but I'll do my best:
I've got around 147 sub routines that do the same thing but with different URLs. Is there a way to use a loop to say 'Hey, for each URL in the PUBLIC_Declarations sub routine do this with it and then stop at the end'.
All 147 sub routines look like this with the only thing changing being the MyURL_URL and the Call Next_Subroutine:
The URL string comes from a sub routine called PUBLIC_Declarations and looks this:
These all take quite a bit of time to set-up and run so my questions are:
1) Could I do a 'For Each URL in PUBLIC_Declarations DO This_Sub' and just have 1 subroutine that is used for each URL?
1a) If so does anyone know how I would do that or have some links?
2) Is this the most efficient way of doing these queries or is there a more efficient method I could use? I'm no expert and have had a lot of help from Mr Excel forum goers over the years to actually get this to work as it stands now.
Thanks for reading and sorry if it's not clear what I'm asking.
I've got around 147 sub routines that do the same thing but with different URLs. Is there a way to use a loop to say 'Hey, for each URL in the PUBLIC_Declarations sub routine do this with it and then stop at the end'.
All 147 sub routines look like this with the only thing changing being the MyURL_URL and the Call Next_Subroutine:
Code:
Sub My_Subroutine_Web()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Application.EnableEvents = False
Application.Calculation = xlCalculationManual
Call Worksheet_Maintenance
(This just does some stuff with the worksheets ready for the data to be handled)
'URLs stored in URL_Variables Module
With ActiveSheet.QueryTables.Add(Connection:=MyURL_URL, Destination:=Range("$A$1"))
.Name = "MrExcel"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = False
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlEntirePage
.WebFormatting = xlWebFormattingNone
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
RawItemName = ActiveSheet.Range("A7").Value
Result = Trim(Split(RawItemName, "-")(0))
ItemName = Result
Rows("1:14").EntireRow.Delete
Call Data_Preparation
(This just trims and gets the data I want in the form I want)
Application.ScreenUpdating = True
Call Next_Subroutine
End Sub
The URL string comes from a sub routine called PUBLIC_Declarations and looks this:
Code:
Public Const MyURL_URL As String = "URL;http://mrexcel.com"
Public Const MyURL_URL As String = "URL;http://mrexcel.com"
Public Const MyURL_URL As String = "URL;http://mrexcel.com"
These all take quite a bit of time to set-up and run so my questions are:
1) Could I do a 'For Each URL in PUBLIC_Declarations DO This_Sub' and just have 1 subroutine that is used for each URL?
1a) If so does anyone know how I would do that or have some links?
2) Is this the most efficient way of doing these queries or is there a more efficient method I could use? I'm no expert and have had a lot of help from Mr Excel forum goers over the years to actually get this to work as it stands now.
Thanks for reading and sorry if it's not clear what I'm asking.