简体   繁体   中英

How can I open an IQY file without being prompted for a destination?

I am automating a process where I open several IQY files and paste them into a master worksheet in excel. Currently the process is manual.

I can open the files using VBA, for example:

set sourcebook = workbooks.open("C:\Metrics\sourceFile.iqy")

I've set notifications to false, I've set displayAlerts to false, neither deter the prompt to import data user form. I don't change the settings at all, it's currently set to output the data in a table in a new workbook, which is fine. I just want to remove that decision/click from the process so all I have to do is run the macro and then all the new data is in my master sheet.

Are there modifiers to the .open method that would allow me to pre-determine things like putting the data in a table on a new workbook?

I've considered adding the IQY files as a data source, but I have to send/share this file to many other users who will have no use for those files and also I'm not entirely familiar with adding data sources/connects to be honest.

See the "Using a Dynamic Web Query" section in this link https://msdn.microsoft.com/en-us/library/office/aa203721(v=office.11).aspx

This works for me:

Sub Finder_Get_Query()
    'Edit path to .iqy file, if necessary.
    IQYFile = "C:\Program Files\Microsoft Office\OFFICE11\" & _
       "QUERIES\MSN MoneyCentral Investor Currency Rates.iqy"
    With ActiveSheet.QueryTables.Add(Connection:= _
       "FINDER;" & IQYFile, Destination:=Range("A1"))

        .BackgroundQuery = True
        .TablesOnlyFromHTML = True
        .Refresh BackgroundQuery:=False
        .SaveData = True
    End With
End Sub

Works perfect! With few modifications you can define the target Sheet for the import (in case you have more than one *.IQY file to connect)

strTargetSheet = "Your SheetName"

StrSourceConnection = "Your IQY file location"

make the call from any other procedure ....

Call Finder_Get_Query(strTargetSheet, strSourceConnection)

Sub Finder_Get_Query(strSheet As String, strConnection As String)
Dim IQYFile As String

ThisWorkbook.Sheets(strSheet).Select
 
IQYFile = strConnection
With ActiveSheet.QueryTables.Add(Connection:= _
   "FINDER;" & IQYFile, Destination:=Range("A1"))

    .BackgroundQuery = True
    .TablesOnlyFromHTML = True
    .Refresh BackgroundQuery:=False
    .SaveData = True
End With
End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM