Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Export to Excel template

Status
Not open for further replies.

Drenda

Programmer
Sep 1, 2007
85
GB
Hello

Wonder if someone can help with the following

I have the results of 4 querys that I would like to export to an excell template that is already created and formatted but with blank fields where the data from each of the query results should go in the excell template.
In addition the query results may shrink or expand depending on the number of results in each query.
I'm a novice regarding this and can see how this can be achieved in a macro but I guess there may be some code that can do this. If it helps I have called each Query;
Query A
Query B
Query C
Query D
And have called the excel template "Query results" and Query A should start in Query results cell A1
Query B should start in Query results cell A21
Query C should start in Query results cell A41
Query D should start in Query results cell A61

Any help would be greatly appreciated

Thanks in aniticipation



 



Hi,

I'd do this from Excel, using Data > Import External Data...

You can set up each querytable in the exact location on the sheet, with the exact formatting. The Data > Import External Data > Data Range Parameters can be configured to refresh each querytable anytime the workbook is opened, for instance.

Skip,

[glasses] When a diminutive clarvoyant had disappeared from detention, headlines read...
Small Medium at Large[tongue]
 
Drenda

I would use Excel automation to open the pre-formatted file, a recordset that holds the resultset of Query A and the CopyFromRecordset method of the Range object to dump the first wave of data. Then close the recordset and reopen it with Query B and move one row down, dump the next wave and so on.

When done, close & save workbook, close excel and set all excel object variables created to Nothing
Don't forget also the recordset.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top