VBA - Paste URL in browser to open link

Tony91

New Member
Joined
Jul 22, 2020
Messages
2
Office Version
  1. 2013
Platform
  1. Windows
Hi,

There are a series of reports that I need to download. I'm given a list of reference numbers that happen to be used when downloading my report.

Example:
Reference#: 348956
URL to download: https://www.domain.com/OpenReport.aspx/GID=348956

Since the majority of the URL is static, I used the concatenate function to build the URL
I found that when I write VBA refence the cell with the url, it will open as expected, but I'm presented with a login screen for the application where I get my report.
On the other hand, if I copy and pasted the URL into chrome, it would download the file with no issue. I figure the method VBA uses to open the URL is causing the login screen to display first.

Once I know I can get over this hurdle, I will write a for loop to get each cell in the column. Here is what I wrote just to test if I could open the link I generated

VBA Code:
Sub Report_Link

Dim URL As String
Dim RefID As String

RefID = ActiveCell.Value

URL = "https://www.domain.com/OpenReport.aspx/GID=" & RefID


ActiveWorkbook.FollowHyperlink URL

End Sub
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Welcome

Does this change anything?

VBA Code:
Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Sub test()
Dim IE As Object, HTMLDoc As Object, URL$
Set IE = CreateObject("internetexplorer.application")
URL = "https://www.domain.com/OpenReport.aspx/GID=348956"
With IE
    .navigate (URL)
    .Visible = True
End With
WaitIE IE, 2000
End Sub

Sub WaitIE(IE As Object, Optional time As Long = 250)
Do
    Sleep time
Loop Until IE.readyState = 4 Or Not IE.Busy
End Sub
 
Upvote 0
Warf. This almost does it.
It is opening the link and allowing me to download as expected, however, I get

Run-time error '462':
The remote server machine does not exist or is unavailable

it happens on this line
VBA Code:
Loop Until IE.readyState = 4 Or Not IE.Busy
 
Upvote 0

Forum statistics

Threads
1,214,985
Messages
6,122,605
Members
449,089
Latest member
Motoracer88

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