Forum Discussion
Extract parameter from web query
I have created a web query to look up the users from different groups in a website and saved the query to my desktop. There are a lot of groups that I need to track the users from, and I only need to change part of the web link to access those users. I created a macro to get the web query I saved on my desktop and changed the query parameters to my group names (now each chunk of users are linked to its group name which is the parameter). Then the macro will go to that link to get the users from that specific group for me. After the query has copied the users from the website to excel, I need to have the group name in the column next to the users column(for visualization purposes). Because every time my queries refresh, they insert cells for new users, and I will have to manually update the group name column. I am wondering if there is a way that I can extract the query parameter out or if there is a better way to do it.
Column B will be the input of my web query, and Column C will be the parameters and I want to have them updated accordingly when some users have been added to the group and create new rows.
My macro to trigger web query:
With ActiveSheet.QueryTables.Add(Connection:= _
"FINDER;C:\Users\Desktop\query.iqy", Destination:=Range("$A$2") _
)
.Name = "query"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlSpecifiedTables
.WebFormatting = xlWebFormattingNone
.WebTables = _
"""ctl00_ctl00_ContentPlaceHolderMain_ContentPlaceHolderSearchResult_ctl07_ObjectGrid"""
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
End Sub