Automating Importing IQY Files

jesnyc

New Member
Joined
Jun 10, 2010
Messages
4
I am writing VBA macro in Excel 2003 that includes opening an IQY file. <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
<o:p></o:p>
When I open an IQY file manually, I get a Import Data dialog box that asks<o:p></o:p>
<o:p></o:p>
"Where do you want to put the data?"<o:p></o:p>
- Existing Worksheet<o:p></o:p>
- New Worksheet<o:p></o:p>
- New Workbook<o:p></o:p>
<o:p></o:p>
and a an OK and Cancel button.<o:p></o:p>
<o:p></o:p>
How do I answer New Worksheet and OK using VBA code?<o:p></o:p>
<o:p></o:p>
The VBA to open the file works fine.<o:p></o:p>
Workbooks.Open Filename:="c:\temp\convert\owssvr.iqy"<o:p></o:p>
<o:p></o:p>
I tried adding NewWorksheet =TRUE with no luck.<o:p></o:p>
<o:p></o:p>
Any help would be greatly appreciated. <o:p></o:p>
Sorry. I am sure this is super basic.
 
Last edited:

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Ok, here's a sub that I use that seems to work. You will need to save you're IQY file from your sharepoint site and I've added some variables to ease readability since the CommandText array is like a huge run-on sentence.

Code:
Sub qry_Sharepoint_Pull()
'
Dim sDBFN As String, sParamArray As String, sArgList1 As String, sArgList2 As String

sDBFN = "C:\Users\<username>\Desktop\owssvr.iqy"
sParamArray = ""<LIST><VIEWGUID><list><viewguid>{9A153DE6-214C-40E2-9EB2-xxxxxxxxxxxx}"</VIEWGUID><LISTNAME></viewguid><listname>{F59E78A5-6C3E-49F5-BDB8-xxxxxxxxxxxx}"</LISTNAME></listname>"
  sArgList1 = ""<LISTWEB>mysite:8003/sites/the-sharepoint-thing/_vti_bin"</LISTWEB><LISTSUBWEB></LISTSUBWEB>"
  sArgList2 = "<rootfolder>/sites/PMO/Gate Repository</rootfolder></list>"
    
    Workbooks.OpenDatabase Filename:=sDBFN, _
            CommandText:=Array(sParamArray, _
                    sArgList1, _
                    sArgList2), _
                    CommandType:=5, _
                    ImportDataAs:=xlTable                    
End Sub
You're best bet is to save the owssvr.iqy file to your desktop, record a macro, open the web-query, and pick the options you want when the dialog pops up.
Then stop recording and check the code. That's all I did.
Good luck.</username>
 
Last edited:
Upvote 0
Ok, here's a sub that I use that seems to work. You will need to save you're IQY file from your sharepoint site and I've added some variables to ease readability since the CommandText array is like a huge run-on sentence.

Code:
Sub qry_Sharepoint_Pull()
'
Dim sDBFN As String, sParamArray As String, sArgList1 As String, sArgList2 As String

[SIZE=2]sDBFN = "C:\Users\usernamegoeshere\Desktop\owssvr.iqy"[/SIZE]
[SIZE=2]sParamArray = "<list><viewguid>{9A153DE6-214C-40E2-9EB2-xxxxxxxxxxxx}</viewguid><listname>{F59E78A5-6C3E-49F5-BDB8-xxxxxxxxxxxx}</listname>"</list>[/SIZE]
[SIZE=2]  sArgList1 = "<listweb></listweb>[/SIZE]mysite://sites/the-sharepoint-thing/_vti_bin<listsubweb></listsubweb>"
[SIZE=2]  sArgList2 = "<rootfolder>/sites/the-root-folder/where-your/sharepoint_list-resides</rootfolder>"[/SIZE]
[SIZE=2]
[/SIZE]
<username>[SIZE=2]
   Workbooks.OpenDatabase Filename:=sDBFN, _
            CommandText:=Array(sParamArray, _
                    sArgList1, _
                    sArgList2), _
                    CommandType:=5, _
                    ImportDataAs:=xlTable                    
End Sub[/SIZE][FONT=lucida console]
[/FONT]
You're best bet is to save the owssvr.iqy file to your desktop, record a macro, open the web-query, and pick the options you want when the dialog pops up.
Then stop recording and check the code. That's all I did.
Good luck.

PS: 10 minutes to edit a post?! are you kidding me? it took me longer than that just to format it...
Admin, please delete my previous post.

</username>
 
Upvote 0
Thanks so much for your reply. It seems my previous thank you back in May never went through.
 
Upvote 0

Forum statistics

Threads
1,223,230
Messages
6,170,883
Members
452,364
Latest member
springate

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