473,395 Members | 1,972 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,395 software developers and data experts.

How to specify Range when exporting to Excel with JET?

I use a complied query to export to Excel like this:

SELECT * INTO [Excel 8.0;Database=C:\MyExcelWorkbook.XLS].[Sheet1]
FROM tblExcelData;

But I have a situation where I need to export several tables into the same
worksheet. The idea is to have each contiguous block of data on the
worksheet separated by 50 or so rows so a graph can be inserted between each
set of data.

The problem with this:

lngA = 64
r = 10
cc = 12 +16
For i = 1 To whatever
strRange = strSheetName & "!" & Chr(lngA + 16) & _
r & ":" & Chr(lngA + cc) & rc
DoCmd.TransferSpreadsheet _
TransferType:=acExport, _
SpreadSheetType:=acSpreadsheetTypeExcel8, _
TableName:="tblExcelData" & i, _
FileName:="C:\MyExcelWorkbook.xls", _
HasFieldNames:=True, _
Range:=strRange
r = r + 50
rc = rc + 50
Next

is that the worksheet must already exist in the workbook. Otherwise
DoCmd.TransferSpreadsheet fails.

I've tried this:

SELECT * INTO [Excel
8.0;Database=C:\MyExcelWorkbook.XLS].[Sheet1]!P10:U24
FROM tblExcelData;

but no luck.

Can I specify a range when exporting to Excel with JET? Is there a way to
get TransferSpreadsheet to create the worksheet if it does not already
exist?

Thanks in advance.
Nov 13 '05 #1
2 3025
On Sat, 11 Jun 2005 11:27:00 GMT, deko wrote:
I use a complied query to export to Excel like this:

SELECT * INTO [Excel 8.0;Database=C:\MyExcelWorkbook.XLS].[Sheet1]
FROM tblExcelData;

But I have a situation where I need to export several tables into the same
worksheet. The idea is to have each contiguous block of data on the
worksheet separated by 50 or so rows so a graph can be inserted between each
set of data.

The problem with this:

lngA = 64
r = 10
cc = 12 +16
For i = 1 To whatever
strRange = strSheetName & "!" & Chr(lngA + 16) & _
r & ":" & Chr(lngA + cc) & rc
DoCmd.TransferSpreadsheet _
TransferType:=acExport, _
SpreadSheetType:=acSpreadsheetTypeExcel8, _
TableName:="tblExcelData" & i, _
FileName:="C:\MyExcelWorkbook.xls", _
HasFieldNames:=True, _
Range:=strRange
r = r + 50
rc = rc + 50
Next

is that the worksheet must already exist in the workbook. Otherwise
DoCmd.TransferSpreadsheet fails.

I've tried this:

SELECT * INTO [Excel
8.0;Database=C:\MyExcelWorkbook.XLS].[Sheet1]!P10:U24
FROM tblExcelData;

but no luck.

Can I specify a range when exporting to Excel with JET? Is there a way to
get TransferSpreadsheet to create the worksheet if it does not already
exist?

Thanks in advance.


VBA help is quite clear on this:

Range Optional Variant. A string expression that's a valid range of
cells or the name of a range in the spreadsheet. This argument applies
only to importing. Leave this argument blank to import the entire
spreadsheet. >>> When you export to a spreadsheet, you must leave this
argument blank. If you enter a range, the export will fail.<<<

What I would do is transfer each group of data into a separate
worksheet, then using code from within Excel, cut and paste into
whatever cells you want on the worksheet you want.
You can use the Excel Record New Macro once to get the code needed,
then modify it if necessary.

--
Fred
Please only reply to this newsgroup.
I do not reply to personal email.
Nov 13 '05 #2
> VBA help is quite clear on this:

Indeed it is:

http://msdn.microsoft.com/library/de...HV05186520.asp

The funny thing is, I've been testing for a while now and it seems to be
working fine. Granted, my development workstation has all the latest and
greatest software. It will be interesting to see what happens on
older/unpatched systems.

This is the first "reverse bug" (where something works that's not supposed
to) that I've ever discovered. Dare I include this code in a production
release? hmmm......
What I would do is transfer each group of data into a separate
worksheet, then using code from within Excel, cut and paste into
whatever cells you want on the worksheet you want.
You can use the Excel Record New Macro once to get the code needed,
then modify it if necessary.


That makes sense. If I can get my unsupported code to break, that's
probably what I'll do.

Below is the actual code I'm using. I create the worksheet with JET by
inserting a one-cell string in A1.

Private Const P As Long = 80

Do While Not rstWorksheets.EOF

'TransferSpreadsheet requires the worksheet to already exist
strSql = "SELECT """" AS " & strTitle & " INTO " & _
"[Excel 8.0;Database=" & strXlsPath & "].[" & _
strSheetNameID & "]"
db.Execute (strSql), dbFailOnError
cc = bytDie + 2 'column count
fr = 7 'first row
'increment row count by 1 to include header row
'(all tables will have the same number of rows)
rc = DCount("DateTime", "tblExcelData1") + 1
lr1 = rc + 6 'initial last row
'loop through anywhere from 1 to 15 or so tables
For b = 1 To bytSite
If b = 1 Then lr = lr1
strRange = Chr(P) & fr & ":" & Chr(P + cc) & lr
Debug.Print strRange
DoCmd.TransferSpreadsheet _
TransferType:=acExport, _
SpreadSheetType:=acSpreadsheetTypeExcel8, _
TableName:="tblExcelData" & b, _
Filename:=strXlsPath, _
HasFieldNames:=True, _
Range:=strSheetNameID & "!" & strRange
If rc < 36 Then
fr = fr + 42
Else
fr = lr + 7
End If
If rc < 36 Then
lr = lr + 42
Else
lr = lr + 42 + (rc - 36)
End If
'save ranges for creating charts later
Call basHandler.Logger(strSheetNameID, strRange, _
strParamName, strSysId, lngPid, , 120)
Next

Loop
Nov 13 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: sridevi | last post by:
Hello How to export data from ms-access database to excel worksheet using ASP. mainly i need to export data to multiple worksheets. it is very urgent to us. i have a sample code which works...
2
by: G | last post by:
When I export data from access to excel by with "export" or "Analyze with" I seem to loose parts of some fields (long text strings). Is there a way to export it all to excel? Thanks G
2
by: Kenneth | last post by:
How do I remove the limitation in Access that deny me from exporting 24000 rows and 17 columns (in a query) into Excel? Kenneth
1
by: ad | last post by:
I use the code below to export the content of a data set to Excel, the code come form http://www.dotnetjohn.com/articles.aspx?articleid=36 But it always use the web form's name as the default...
2
by: andrew007 | last post by:
Is there anyway that the page can automatically print while exporting excel from datagrid. My page does exporting to excel from datagrid on the fly but I want to add a feature to print...
1
by: Red | last post by:
Ok, yada yada yada, I know this is the Access group, however, I need help in Excel :D Here's the thing, I'm exporting data to excel (From Access), adding code from a string, and executing...
2
by: Snozz | last post by:
The short of it: If you needed to import a CSV file of a certain structure on a regular basis(say 32 csv files, each to one a table in 32 databases), what would be your first instinct on how to...
1
by: Kathy | last post by:
I have a number of reports in a MS Access application that have a logo picture embedded in the report. When I run the report and choose File, then Export to Excel, I get an error indicating...
7
by: leninv | last post by:
Hi, I have the following code where 'recs' is a record set. For i=0 to recs.Fields.Count - 1 if i = 0 then pindnt = string(itmlvl*2," ") response.write pindnt &...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
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.