473,406 Members | 2,217 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Code Help: Pasting Query Contents to Spreadsheet

46
Hello, I need a little help with some code. I am trying to export the contents of a query to an Excel spreadsheet. The code below will find a named cell as the starting point and paste contents. Right now, it's just set to "test" in a named cell called "TestCell". How would I go about pasting the contents of a query, call it "qry_test"?

Expand|Select|Wrap|Line Numbers
  1. Dim obj As Object
  2. Set obj = GetObject("C:\file path")
  3. obj.Application.Visible = True
  4. obj.Windows(1).Visible = True
  5. obj.Application.Goto "TestCell"
  6. obj.Application.ActiveCell.FormulaR1C1 = "test"
  7. End Sub
Thank you!
Nov 23 '07 #1
3 1539
Three thoughts. Excuse me if this is too obvious or you don't like the way the data appears in Excel...

First, if you are viewing the query on screen, from the Access menu bar you can click Tools ~ Office Links ~ Analyze it with Microsoft Excel, and Access will create an Excel file that matches your query & place it in your default directory, usually My Documents.

Second, it you already have a pre-built Excel file with formatting, you can open Excel and create a link from Excel to Access - from the Excel menu bar click

Data ~ Import External Data ~ New Database Query, answer the seemingly endless stream of questions :-) Haven't done this with Excel for quite some time, but here is a link that describes how to connect from Excel to SQL Server, maybe that will help:

Create SQL Server database query with MS Excel

and then place your data to begin at the desired spot. You will have the option to refresh the data when you open Excel, or you can make it refresh on demand. This will preserve most of the formatting.

Lastly, if this is too much effort, simpy view your query on screen, press Ctrl-A to select all rows & all data, then open a new Excel workbook & paste the data in there. (However, this option will not work if your query is a SQL pass-thru, you'll get 'operation on this type of object is not supported')

In any othese example, remember that Excel 2003 can accept 65,635 rows of data but Excel 2007 can handle just over a million rows.
Nov 24 '07 #2
QVeen72
1,445 Expert 1GB
Hi,

In Access, Design a Macro which will transfer the contents..
Create New Macro Action = "TransferSpreadSheet"
Below Properties Select :
TransferType =Export
Spread Sheet Type : Excel 5-7
TableName : Query1
FileName : C:\MyExcel
HasFields = Yes

and Save the Macro. Just Run this Macro, and the datas will be exported..

Regards
Veena
Nov 24 '07 #3
jarekz
13
I think the best way to export the contents of a query to an Excel spreadsheet is by using DoCmd.Transferspreadsheet in your VBA code. It is better than doing it by macro, because in the code you can choose whatever path and filename you wish to export the data to. In Macro the filename and path is always the same and can't be changed.

But I don't know if it is possible to export the data to a specific cell in an Excel spreadsheet. I suggest you read MS Access Help on DoCmd.Transferspreadsheet. Good luck!

Jarek
Nov 25 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Paolo | last post by:
Friends, I need help with some code to export different tables to a single spreadsheet in Excel. My excel file is named REPORT and the spreadsheet is named CLIENTS. I do have the code to export...
3
by: Mads Petersen | last post by:
I'm stuck in this code. Hope you can and will help me. I launch it from excel. I have made the following code work, but not as i whant. I need the ranges to be working with something like xlDown....
2
by: Peter | last post by:
I have a Query called "DATA" that contains 60 records with 6 fields of data. I want to dump the query results into a specific xls file. The first worksheet of this xls file has space for the...
3
by: Larry Rekow | last post by:
I've built various web apps using Frontpage and/or ASP and Access, but now I'm trying to figure a way to do the following, perhaps in ASP.Net My friend gets parts lists in invoices (they are in...
3
by: TM | last post by:
Is there any way that I can take the records from a datagrid and paste them into an Excel sheet, then print preview or print the sheet ? Is there any way I can sort the sheet before I print it ?...
4
by: bill_nirl | last post by:
Hi all, can anyone help. i have a spreasheet (set up by a looney) they have in the surname field, the surname then forename. What sort of code would i need to use to sort this out. It looks...
1
by: garry.oxnard | last post by:
Can anyone help me to solve a problem which involves switching from Access to Excel (then back to Access) programatically please? I have an Excel template which, on open, also opens an Access...
1
by: Tim Marshall | last post by:
In my not too successful attempts to get an OLE chart object (Graph 11.0) that has been manipulated on a form to be reproduced on a report, I am considering the following procedure. First copy the...
5
by: exhuma.twn | last post by:
As many might know, windows allows to copy an image into the clipboard by pressing the "Print Screen" button on the keyboard. Is it possible to paste such an image from the clipboard into a "Text"...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.