Stumped by External Data Range Properties & Save query definition

Shiseiji

Board Regular
Joined
Oct 23, 2009
Messages
143
Excel 2016. I've been testing some VBA and a simple text import stopped working. I'd forgotten that despite including:
VBA Code:
If ThisWs.QueryTables.Count > 0 Then
     ThisWs.QueryTables(1).Delete
  End If
  If ThisWb.Connections.Count > 0 Then
     ThisWb.Connections.Delete
  End If
and verifying there were no queries or connections, there is in fact still an active query. Found by right clicking in a cell in the data range and checking the Data Range Properties that then reports the External Data Range Properties where a query is listed and a check box option for Save query definition that was checked by default.

Fortunately I have no holes in the first and last columns/rows of the text file I'm importing, so I'm able to use last row and last column to make a table I then copy and paste as values. That removes the query, copy and paste cells would probably work too.

But is there some VB that will change the Save query definition selection to False?

And my teeth clenching question "Who dreamed this up?"

TIA

Ron
 

Some videos you may like

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).

Shiseiji

Board Regular
Joined
Oct 23, 2009
Messages
143
I've got a partial answer for better coders than I am. The issue is that I'm importing a text file using the fileobject of DateModified. Once that fileobject is set, the Power Query is set to always use the query by default. One possible answer is to use what was given to break a connection to a Sharepoint site, ut I've learned my problem is a common one and killing the PowerQuery QueryTable is apparently something that MS thought no one would ever want to do.
Dim objListObj As ListObject
Dim objQryTbl As QueryTable

But now we are into objects and I'm bad about keeping them straight in my head. The code:
Set objListObj = ThisWs.ListObjects(1)
objListObj.Unlink

returns the "Object required"

I have other code that will import without fileObject. Or else will have to use a file that's constantly updated so the query link won't need to change.

Very interested in the answer if anyone has one.
 

Watch MrExcel Video

Forum statistics

Threads
1,126,963
Messages
5,621,854
Members
415,862
Latest member
nascaline

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
Top