Using a URL from a Cell in a Web query macro

bracken752

New Member
Joined
Aug 15, 2013
Messages
44
Hey all,

I hope you're all well and are able to help me out (yet again) for my new project (I will soon be able to help people instead of being a pain in your ***** lol).

I am using =CONCATENATE to create a URL based on the outcome of a drop down menu (For example, select "Barry Smith" from the drop down, using vlookup this finds his "ID number" and using =CONCATENATE I put this into the URL.

The issue is now that I want to use a web query and take advantage of the cell where I have used =CONCATENATE (For example Cell A1)

The webquery needs to create a new worksheet and then query the URL that is in Cell A1, I currently do this manually via macro record which is as follows:

Code:
    ActiveWorkbook.Worksheets.Add    With ActiveSheet.QueryTables.Add(Connection:="URL;http://www.REMOVED.net/RestrictedPages/UserDetail.aspx?userID=36", _
        Destination:=Range("$B$2"))
        .Name = "UserDetail.aspx?userID=36"
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .BackgroundQuery = True
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .WebSelectionType = xlAllTables
        .WebFormatting = xlWebFormattingNone
        .WebPreFormattedTextToColumns = True
        .WebConsecutiveDelimitersAsOne = True
        .WebSingleBlockTextImport = False
        .WebDisableDateRecognition = False
        .WebDisableRedirections = False
        .Refresh BackgroundQuery:=False

Any ideas? I would love you long time if you could help me out here, I think my head will explode if I look at anymore VBA lol.

Kindest Regards,
JB
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
The issue is now that I want to use a web query and take advantage of the cell where I have used =CONCATENATE (For example Cell A1)
If this A1 cell is on Sheet1, then:
Code:
Sub WQ()
    ActiveWorkbook.Worksheets.Add
    With ActiveSheet.QueryTables.Add(Connection:="URL;" & Worksheets("Sheet1").Range("A1").Value, _
        Destination:=Range("$B$2"))
        .Name = "UserDetail.aspx?userID=36"
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .BackgroundQuery = True
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .WebSelectionType = xlAllTables
        .WebFormatting = xlWebFormattingNone
        .WebPreFormattedTextToColumns = True
        .WebConsecutiveDelimitersAsOne = True
        .WebSingleBlockTextImport = False
        .WebDisableDateRecognition = False
        .WebDisableRedirections = False
        .Refresh BackgroundQuery:=False
    End With
End Sub
 
Upvote 0
Hey John_w,

Thank you for your help on this matter, but sadly doesn't seem to work, it opens a new sheet (Which is what I want) starts the web query and looks like it does something but just leaves the new sheet blank.

Any other ideas?

Sorry to be a pain.

Regards
JB
 
Upvote 0
Got it working yay :). Using a copy and CutCopyMode functions.

Code:
ActiveWorkbook.Worksheets.AddSelection.Copy
Application.CutCopyMode = False
Range("S12").Select
With ActiveSheet.QueryTables.Add(Connection:="URL;" & Sheets("Sheet1").Range("S12").Value, Destination:=Range("A1"))
.Name = "names"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlEntirePage
.WebFormatting = xlWebFormattingNone
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
End Sub

I have now encountered a new problem but I will create a new post for this and mark this as solved.
 
Upvote 0

Forum statistics

Threads
1,215,987
Messages
6,128,122
Members
449,424
Latest member
zephyrunimpressively

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top