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

Transfer array to excel worksheet using vb in ms access

Greetings
This is one of those Access is not closing Excel problems.
The first time through the code works fine. The second time there is a problem.
After lots of combinations, I finally determined that if I take out the line that copies the temp array to cells in a worksheet, Access will close the Excel file. If the line is there, Excel remains open and blocks more runs of the same procedure. If I close Access, Excel gets closed. Looks like somehow Access is calling another copy of Excel. Is there a way to keep the array processing and copy in the Excel that is open? I saw other web articles about explicit references, but I do not know how to make an explicit reference to TempArray to get it to stay in the open copy of Excel.
Thanks
Blaine
[code]
Private Sub cmdExcelTest3_Click()
On Error GoTo Err_cmdExcelTest3_Click
'----------
'This procedure transfers an array to a spreadsheet
'-----------

'Setup the workbook variables
Dim objExcel As Excel.Application
Dim objListBook As Excel.Workbook
Dim objListSheet As Excel.Worksheet
Dim FileInfoRange As Excel.Range
'Setup the range variables
Dim CellsDown As Long, CellsAcross As Integer
Dim r As Long, c As Integer 'r=row, c=column
'Setup the temp array variable
Dim TempArray() As String
'Create the Excel object
Set objExcel = New Excel.Application
objExcel.Visible = True
'Setup the workbook and worksheet
With objExcel
Set objListBook = .Workbooks.Add
On Error Resume Next
Set objListSheet = objListBook.Worksheets.Add
objListSheet.Name = "Source Files"
End With 'for creating workbook and worksheet
'Set the dimensions of the range
CellsDown = 20
CellsAcross = 6
'Redimension temp array
ReDim TempArray(1 To CellsDown, 1 To CellsAcross)
'Activate the workbook and worksheet
objListSheet.activate
On Error GoTo Err_cmdExcelTest3_Click
'Fill the temp array
Dim intValue_r As Integer 'number generator
Dim intValue_c As Integer
r = 1 'set the starting value
c = 1 'set the starting value
For r = 1 To CellsDown
intValue_r = intValue_r + 1
For c = 1 To CellsAcross
intValue_c = intValue_c + 1
TempArray(r, c) = intValue_r + intValue_c
Next c
Next r
'Transfer temp array to worksheet via FileInfoRange
'This is the problem line.
'FileInfoRange.Value = TempArray
objExcel.Application.ActiveSheet.Range(Cells(3, 1), _
Cells(CellsDown, CellsAcross)).Value = TempArray
'Save the workbook
'Create the filename
strListofFiles = "List of Source Files.xls"
'Save the workbook to the filename
objListBook.SaveAs strListofFiles
On Error GoTo Err_cmdExcelTest3_Click
'Clear the object variables.
Erase TempArray()
Set FileInfoRange = Nothing
Set objListSheet = Nothing
Set objListBook = Nothing
objExcel.DisplayAlerts = True
objExcel.Quit
Set objExcel = Nothing
Exit_cmdExcelTest3_Click:
Exit Sub
Err_cmdExcelTest3_Click:
'Clear the variables
Set ListSheet = Nothing
Set ListBook = Nothing
objExcel.Quit
Set objExcel = Nothing
Erase TempArray()
MsgBox Err.Description
Resume Exit_cmdExcelTest3_Click
End Sub

[CODE}
May 12 '07 #1
0 3012

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

Similar topics

13
by: Allison Bailey | last post by:
Hi Folks, I'm a brand new Python programmer, so please point me in the right direction if this is not the best forum for this question.... I would like to open an existing MS Excel spreadsheet...
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...
11
by: Mr. Smith | last post by:
Hello all, My code can successfully open, write to, format and save several worksheets in a workbook then save it by a given name, close and quit excel. My problem is that if I try and do it...
14
by: pmud | last post by:
Hi, I need to use an Excel Sheet in ASP.NET application so that the users can enter (copy, paste ) large number of rows in this Excel Sheet. Also, Whatever the USER ENETRS needs to go to the...
3
by: James Wong | last post by:
Dear all, I have an old VB6 application which can create and access Excel object. The basic definition statements are as follows: Dim appExcel As Object Dim wkb1 As Excel.Workbook Dim wks1...
5
by: hmiller | last post by:
Hey there folks: I have been trying to get this work for about a week now. I'm new to VBA... I am trying to transfer a populated table in Access to an existing, but blank, Excel worksheet. I...
3
by: JohnM | last post by:
I can transfer from a query with DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel8, "Filenam", CPath, True I would like to use a form for the user to select and order data then...
1
by: smaczylo | last post by:
Hello, I've recently been asked to work with Microsoft Access, and while I feel quite comfortable with Excel, I'm at a complete loss with databases. If someone could help me with this issue I'm...
5
by: billa856 | last post by:
Hi I am totaly new to MS Access. I have one worksheet in excel in which I have data of company's inventory. I want to know can I transfer data from a form made in MS Access to the Excel worksheet?...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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...

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.