Batch replacing External Connection Stream

fluffynicesheep

Board Regular
Joined
Oct 27, 2009
Messages
69
Hi,

I currently have a spreadsheet that includes lots of pages imported from external data (an external website).

The links that I used were similar to:

https://www.twitrss.me/twitter_user_to_rss/?user=barkingcollege

However recently there has been an issue with a security certificate on the website, so unless I manually click [ok], when excel opens - the data can no longer refresh in the background overnight.

What seems to work is if I remove the s from the link and replace with:

http://www.twitrss.me/twitter_user_to_rss/?user=barkingcollege

With hundreds of links this would take an age to do manually, so what I'm after is a piece of code that would allow me to cycle through all of my connection strings and do a Find and Replace ...

If it finds any link containing twitrss.me it will simply replace the https with http

Hopefully someone can help?

Thanks
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Try this macro.
VBA Code:
Public Sub Change_Query_Connections()

    Dim ws As Worksheet
    Dim qt As QueryTable
    
    For Each ws In ActiveWorkbook.Worksheets
        For Each qt In ws.QueryTables
            qt.Connection = Replace(qt.Connection, "https://", "http://")
            qt.Refresh BackgroundQuery:=False
        Next
    Next
    
End Sub
 
Upvote 0
Try this macro.
VBA Code:
Public Sub Change_Query_Connections()

    Dim ws As Worksheet
    Dim qt As QueryTable
   
    For Each ws In ActiveWorkbook.Worksheets
        For Each qt In ws.QueryTables
            qt.Connection = Replace(qt.Connection, "https://", "http://")
            qt.Refresh BackgroundQuery:=False
        Next
    Next
   
End Sub


Hi John,

Thanks for the reply.

Unfortunately I've added this and run it and it doesn't appear to do anything. I have had a look back at the properties in the connection settings menu and it is still showing the link with the s at the end.
 
Upvote 0
Hi John,

I am using Excel 2016.

I clicked on [data] and then [from web] then I added the weblink:

https://www.twitrss.me/twitter_user_to_rss/?user=barkingcollege

Originally this all worked fine, but as you can see when I try to add it now, I get this message:

Cert.JPG


So any new links, I'm simply changing to http://www.twitrss.me/twitter_user_to_rss/?user=barkingcollege and it goes in and updates fine.

So, in order to update this workbook I now have to manually click [Yes] once.

This would be fine, but I would like the links to auto refresh overnight - so in order to do this automatically I have to get rid of this security alert.

I know moving forward that removing the S works fine and the cert will no longer show .... but it's changing all the previous weblinks that is gong to be so time consuming!

I basically need to change https: to http: in the below location for around 1000 different connections.

Capture.JPG



I hope this helps
 
Upvote 0
Your screenshot shows the connection is using a web query, and my macro changes the connection string for every web query on every sheet, so I don't understand why it isn't changing https to http.

Try this macro, which is another way of changing web queries, but from the workbook connections. It also displays details of each web query connection.

VBA Code:
Public Sub Change_Workbook_Connections()

    Dim wbConn As WorkbookConnection
    Dim wbConnRange As Range
    Dim qt As QueryTable
    Dim prevConnection As String
    
    For Each wbConn In ActiveWorkbook.Connections
        Select Case wbConn.Type
            Case Is = xlConnectionTypeWEB, xlConnectionTypeXMLMAP
                For Each wbConnRange In wbConn.Ranges
                    Set qt = wbConnRange.QueryTable
                    prevConnection = qt.Connection
                    qt.Connection = Replace(qt.Connection, "https://", "http://", 1, , vbTextCompare)
                    MsgBox "Connection Name: " & wbConn.Name & vbCrLf & _
                        "Type: " & wbConn.Type & vbCrLf & _
                        "Sheet: " & wbConnRange.Parent.Name & ", Range: " & wbConnRange.Address & vbCrLf & _
                        "Previous connection: " & prevConnection & vbCrLf & _
                        "Current connection: " & qt.Connection
                Next
            Case Else
                MsgBox "Uncoded WorkbookConnection Type " & wbConn.Type
        End Select
    Next
    
End Sub
 
Upvote 0
Hi John,

I've run this and a debug pops up straight way. The yellow line that is highlighted is:

Set qt = wbConnRange.QueryTable
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,915
Members
452,366
Latest member
TePunaBloke

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