473,706 Members | 2,058 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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: \MyExcelWorkboo k.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.TransferS preadsheet _
TransferType:=a cExport, _
SpreadSheetType :=acSpreadsheet TypeExcel8, _
TableName:="tbl ExcelData" & i, _
FileName:="C:\M yExcelWorkbook. xls", _
HasFieldNames:= True, _
Range:=strRange
r = r + 50
rc = rc + 50
Next

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

I've tried this:

SELECT * INTO [Excel
8.0;Database=C: \MyExcelWorkboo k.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 TransferSpreads heet to create the worksheet if it does not already
exist?

Thanks in advance.
Nov 13 '05 #1
2 3060
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: \MyExcelWorkboo k.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.TransferS preadsheet _
TransferType:=a cExport, _
SpreadSheetType :=acSpreadsheet TypeExcel8, _
TableName:="tbl ExcelData" & i, _
FileName:="C:\M yExcelWorkbook. xls", _
HasFieldNames:= True, _
Range:=strRange
r = r + 50
rc = rc + 50
Next

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

I've tried this:

SELECT * INTO [Excel
8.0;Database=C: \MyExcelWorkboo k.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 TransferSpreads heet 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.E OF

'TransferSpread sheet 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("DateTim e", "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.TransferS preadsheet _
TransferType:=a cExport, _
SpreadSheetType :=acSpreadsheet TypeExcel8, _
TableName:="tbl ExcelData" & b, _
Filename:=strXl sPath, _
HasFieldNames:= True, _
Range:=strSheet NameID & "!" & 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.Logg er(strSheetName ID, 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
9244
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 only exporting to single worksheet. but i need to export data to multiple worksheets. it is very urgent to us. so please help me in code.
2
7709
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
8006
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
2319
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 name of excel. Can we specify a meaningful filename before exporting to EXCEL? ------------------------------------------------------------------------------------------- 'first let's clean up the response.object response.Clear()
2
1404
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 automatically during conversion. is it possible?
1
1466
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 the code... no biggie, I do it daily.. my superiors are high on Excel....
2
3181
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 set this up so as to do it reliably and minimize overhead? There are currently no constraints on the destination table. Assume the user or some configuration specifies the database name, server name, and filename+fullpath. The server is SQL...
1
2983
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 "Subscript Out of Range". If I remove the picture from the report, it works fine. I have tried writing code to set the picture field's "Visible" property to false when an export is attempted, but I still get the error.
7
12299
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 & recs(i) else Response.write recs(i)
0
8697
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9287
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9157
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9056
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8999
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6615
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4454
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4710
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3150
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.