troubleshooting Question

Opening Multiple IQY Files for full-page queries, saving one cell

Avatar of Jaron Johnson
Jaron Johnson asked on
Microsoft OfficeMicrosoft ExcelVBA
6 Comments1 Solution652 ViewsLast Modified:
I used a previous expert's answer from Excel 2003, but it doesn't seem to work for 2013.

I have a directory with multiple IQY files. Each one is for an intranet page which has data I need, but isn't broken up into tables. The IQY for each page is set to pull the entire page's data and insert it into column A.

Of all of these cells, I only need one (Cell A159).

I was using:

Sub OpenAllIQY()
Dim FName As String, Path As String
  Path = "C:\Users\jjar\Documents\My Data Sources\"
  FName = Dir(Path & "*.iqy")
  While Len(FName) > 0
    OpenIQY Path & FName
    FName = Dir
    Application.Wait TimeSerial(Hour(Now()), Minute(Now()), Second(Now()) + 5)
  Wend
End Sub
 
Sub OpenIQY(IQYName)
Dim WBN As Workbook
 
  Set WBN = Application.Workbooks.Add
  With WBN.Worksheets(1).QueryTables.Add(Connection:= _
    "FINDER;" & IQYName, Destination:=WBN.Worksheets(1).Range("A1"))
    .Name = "IQY"
    .FieldNames = True
    .RowNumbers = False
    .FillAdjacentFormulas = False
    .PreserveFormatting = False
    .RefreshOnFileOpen = False
    .BackgroundQuery = True
    .RefreshStyle = xlInsertDeleteCells
    .SavePassword = False
    .SaveData = True
    .AdjustColumnWidth = True
    .RefreshPeriod = 0
    .WebSelectionType = xlAllTables
    .WebFormatting = xlWebFormattingNone
    .WebPreFormattedTextToColumns = False
    .WebConsecutiveDelimitersAsOne = True
    .WebSingleBlockTextImport = False
    .WebDisableDateRecognition = False
    .WebDisableRedirections = False
    .Refresh BackgroundQuery:=False
  End With
  WBN.Close SaveChanges:=True, Filename:=Replace(IQYName, ".iqy", "", , , vbTextCompare)
End Sub

To open each IQY file and save the search as an Excel file, which I could then open into workbooks and call the specific cell I needed from each of them into one master workbook. Unfortunately, when I run the above macro, the Excel Files it saves (using my IQY files) are empty.

Even if this were to work, there has to be a more efficient way.
ASKER CERTIFIED SOLUTION
Jamie Garroch (MVP)
PowerPoint Technical Consultant

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 6 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 6 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros