Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default Deleting a query

Hi,

I hope someone could help me this, I have a feeling this
is not possible but anyway, here goes, is it possible to
create a routine for a command button that would prompt
the user to enter a query name(achieved when you right
click on a query and then open Data Range Properties,
this is the actual name of the iqy file)and when the user
enters the name, he can then delete it from it's place on
the spreadsheet(in my case it would be somewhere in sheet
2) and the iqy file stored in the Microsoft/Queries
default folder? Maybe you know another way of handling
it. Either way, I would be truly grateful!!!! Thanks
for your help!

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 599
Default Deleting a query

Rhonda

Here's something to try.

Sub DelQuery()

Dim Fname As String
Dim RngName As String
Dim qt As QueryTable

ChDir "C:\Windows\Application Data\Microsoft\Queries\"

Fname = Application.GetOpenFilename

If Fname < "False" Then
RngName = Left(Dir(Fname), Len(Dir(Fname)) - 4)
For Each qt In ActiveSheet.QueryTables
If qt.ResultRange.Address = ActiveSheet.Range(RngName).Address Then
qt.SaveData = False
ActiveSheet.Range(RngName).ClearContents
ActiveSheet.Names(RngName).Delete
Exit For
End If
Next qt
Kill Fname
End If

End Sub

Excel creates a range name when a query is added to the sheet that is the
same as the iqy file name. This loops through the querytables to find one
with the same range as that range name, then deletes it. The problem that
you may run into is if more than one query is created with the same iqy
file. If you were to delete a query, then create another query with the
same name, it would append an "_1" to the end of the range name which would
cause a problem. Hopefully it will get you started though.

--
Dick Kusleika
MVP - Excel
www.dicks-clicks.com
Post all replies to the newsgroup.

"Rhonda" wrote in message
...
Hi,

I hope someone could help me this, I have a feeling this
is not possible but anyway, here goes, is it possible to
create a routine for a command button that would prompt
the user to enter a query name(achieved when you right
click on a query and then open Data Range Properties,
this is the actual name of the iqy file)and when the user
enters the name, he can then delete it from it's place on
the spreadsheet(in my case it would be somewhere in sheet
2) and the iqy file stored in the Microsoft/Queries
default folder? Maybe you know another way of handling
it. Either way, I would be truly grateful!!!! Thanks
for your help!



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Deleting the text without deleting the formula gems04 Excel Worksheet Functions 3 January 30th 09 11:21 PM
another macro query - deleting a worksheet within a query DavidHawes Excel Discussion (Misc queries) 2 February 26th 07 10:05 AM
Deleting cell data without deleting formula Tom Hall Excel Discussion (Misc queries) 4 October 29th 06 04:07 PM
deleting values in a worksheet without deleting the formulas patti Excel Worksheet Functions 1 October 28th 05 09:49 PM
how prevent formula in cell from deleting when deleting value???? sh-boom New Users to Excel 1 September 30th 05 06:12 PM


All times are GMT +1. The time now is 11:14 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"