Export data from IQY file using a macro in an excel report
Sometimes when I export a data, the tool offers me only to have it in IQY file, in this case, I have to open it and save it as an excel file but most of the time, I don’t need to do that because from my main excel file, this macro will help me to extract the data then copy/paste it to the sheet I want in my main file. In the other hand, if I have to update the data each month, it is best to save it as an xls file then doing a refresh every month.
When I use the macro ?
To export the data from an IQY file to an excel sheet or to save it as an xls file then refreshing every month to get the updated data.
How to create the macro ?
Read How to create, edit, hide and select a macro in an excel report
How to create the button to associate it with the macro ?
Read How to create a button and associated it to a macro in an excel report
How is/are the macro(s) ?
Copy the code below and paste it into your macro. You will see my comments in green if exist so follow the help to adapt to your need.
Sub test() ' change xxx by the file name ' if located to another folder, put IQYFile = "C:\fullpath\xxx.iqy" IQYFile = ThisWorkbook.Path & "\xxx.iqy" ' change yyy by the sheet name where to paste ' if paste to current sheet, put ActiveSheet instead first Worksheets("yyy") ' if paste to current sheet, remove second Worksheets("yyy"). and change A2 by the cell to paste With Worksheets("yyy").QueryTables.Add(Connection:="FINDER;" & IQYFile, Destination:=Worksheets("yyy").Range("A2")) .BackgroundQuery = True .TablesOnlyFromHTML = True .Refresh BackgroundQuery:=False .SaveData = True End With End Sub
This option is good if I have to use only 1 time the file but if every month, I need to download it to get the updated data, I prefer to save it in an excel xlsm file then use it as my main one or to export the data directly into a sheet of my main xlsm file. After that, every month, I just need to refresh the table.
For only 1 single data connection:
Sub test() ' change xxx by the sheet name Worksheets("xxx").Range("A1").ListObject.QueryTable.Refresh End Sub
For all data connection:
Sub test() ' change xxx by the sheet name Worksheets("xxx").Range("A1").Select ActiveWorkbook.RefreshAll End Sub
Instead to refresh via a macro, I can do it with one of those options in the “connection properties”.

Interesting Topics
-
Be successfully certified ITIL 4 Managing Professional
Study, study and study, I couldn’t be successfully certified without studying it, if you are interested...
-
Be successfully certified ITIL 4 Strategic Leader
With my ITIL 4 Managing Professional certification (ITIL MP) in the pocket, it was time to go for the...
-
Hide visual and change background color based on selection
Some small tricks to customize the background colour of a text box...
-
Stacked and clustered column chart or double stacked column chart
In excel, I use a lot the combination of clustered and stacked chart...
-
Refresh Power BI
From the Power BI Service, I can set refresh but, for instance, there is no option to do it monthly or each time a change is made...
-
Power BI alerts to be sent by email from an excel file based on condition
I will explain how to send a list of emails from an excel file after creating alerts...