Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 75
Default edit query without name (or control name at creation) VBA 2007

I need to create a bunch of similarly-structured queries, that query
different workbooks. In Excel 2003, I could create one, then copy it N times
and then go back and edit the copies so they referred to the workbooks that I
copied them to.

As long as the range "query1" was entirely withing the query that I wanted
to edit, a command that started with:

Range("query1").QueryTables.CommandText = ...

would work.

I'm having trouble doing the same thing in 2007; I can't seem to figure out
how to edit a query without the connection name, which Excel seems to be
naming sequentially.

I need to either edit the query without having to provide the name, or I
need to be able to name the connection at the time it's being created
(through VBA). When I record myself editing a query, it's always referring to
"Query From Excel Files###". Even when I create the query with a different
name for the connection, it records as creating a query named "Query From
Excel Files###" and then renaming it to the name I want.

How do I get around this, short of keeping track of exactly which queries
are created in which order?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 50
Default edit query without name (or control name at creation) VBA 2007

On Feb 4, 2:18*am, Bobby wrote:
I need to create a bunch of similarly-structured queries, that query
different workbooks. In Excel 2003, I could create one, then copy it N times
and then go back and edit the copies so they referred to the workbooks that I
copied them to.

As long as the range "query1" was entirely withing the query that I wanted
to edit, a command that started with:

* * Range("query1").QueryTables.CommandText = ...

would work.

I'm having trouble doing the same thing in 2007; I can't seem to figure out
how to edit a query without the connection name, which Excel seems to be
naming sequentially.

I need to either edit the query without having to provide the name, or I
need to be able to name the connection at the time it's being created
(through VBA). When I record myself editing a query, it's always referring to
"Query From Excel Files###". Even when I create the query with a different
name for the connection, it records as creating a query named "Query From
Excel Files###" and then renaming it to the name I want.

How do I get around this, short of keeping track of exactly which queries
are created in which order?


Assign newly created query to object (or objects, if you need to
access all of them):
dim MyQuery as QueryTable;
dim rs,rs2 as RecordSet
set MyQuery=QueryTables.Add(rs, Range("A1"))
MyQuery.Refresh
'Do something
set MyQuery=QueryTables.Add(rs, Range("B2"))
MyQuery.Refresh
'Do something
set MyQuery=QueryTables.Add(rs2, Range("A1"))
MyQuery.Refresh
'Do something
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
"edit query" button in Excel 2007 has been hidden Andre Ranieri Excel Worksheet Functions 2 May 2nd 23 03:44 AM
edit query in Escel 2007 pulled from Access? MAF Excel Discussion (Misc queries) 1 April 21st 09 08:11 PM
excel 2007 right click edit query Koppite412 Excel Worksheet Functions 1 September 3rd 08 06:26 PM
Creation and property manipulation of Control Checkbox using VB BRG Excel Programming 2 August 5th 08 09:25 PM
Dynamic Control Creation in VBA Asif[_3_] Excel Programming 2 December 9th 03 07:35 PM


All times are GMT +1. The time now is 06:42 PM.

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

About Us

"It's about Microsoft Excel"