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

TransferSpreadsheet destroys Excel

Hello! My Code destroys Excel's normal work.After running this code I
acan' open excel file as normal. Do you know why? Please, answer.

Public Function import_test_1()
Dim objXL As Object
Dim objWB As Object
'Dim objXL As Excel.Application
'Dim objWB As Excel.Workbook
Dim strFile As String
Dim xlPath As String
Dim xlFile As String
Dim i As Integer

xlPath = "H:\ANNETTEB\financial statements as of feb 2008\TEMPLATES\"
'
'************************************************* ************************************************** ****
' 1- open each source file
' 2- insert 1 new sheet=template (give the same name to all of them!)
' 3- copy "outputs' sheet and PAste Special (Value,Skip
Blamks,Transposal)into "TEMPLATE" sheet
' 4 save file
' 5-after all sources are prepared- run
docmd.transferSpreadsheet ...for this folder
' 6 then open just created new table and edit it
'
'************************************************* ************************************************** ****

xlFile = Dir(xlPath & "*.xls")
'
i = 1

Set objXL = CreateObject("Excel.Application")
While xlFile <""

strFile = xlPath & xlFile

Set objWB = objXL.Workbooks.Open(strFile)

' For i = 1 To objWB.Worksheets.Count
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9,
objWB.Worksheets(3).Name & i, strFile, True, objWB.Worksheets(3).Name
& "!"
' DoCmd.TransferDatabase ,,,,
' Next i
objWB.Close
'objXL.Quit
xlFile = Dir
i = i + 1
Wend
objXL.Quit
Set objWB = Nothing
Set objXL = Nothing
End Function
Sep 10 '08 #1
2 2487
Here is the catch with TransferSpreadsheet - you can only use it once
per workbook. You are trying to use it in a loop - won't work. If your
data is small (a few dozen lines per sheet) you may get away with just
using Automation - which it appears to were trying to combine automation
with TransferSpreadsheet. But you have to use the Excel Range object.
If you have more than a few dozen rows which you need to transfer - then
you need to use ADO. Look at MSDN on ADO usage with Excel. ADO is way
faster than automation for transferring large amouhnts of data from
Access to Excel, but a bit more sophisticated than Automation.
*** Sent via Developersdex http://www.developersdex.com ***
Sep 10 '08 #2
Upon re-reading your post - it looks like you are trying to import data
from Excel. In that case you can use automation and the Excel Range
object to select the UsedRange. Then you can use DAO code (native to
Access) to loop through the Range object and write the data to a table.
This way you can loop through the Excel Sheets collection.

Rich

*** Sent via Developersdex http://www.developersdex.com ***
Sep 10 '08 #3

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

Similar topics

1
by: O'Donnell Tribunal | last post by:
Hello Everybody, I am using the TransferSpreadsheet method to import spreadsheets for processing. say my code looks like this: DoCmd.TransferSpreadsheet acImport, 0, _ "tbltempImport1", ""...
0
by: Mick Hardy | last post by:
Hi, Has anyone seen this weird behaviour or have any suggestions or can anyone reproduce it? The history: I converted a large third party DB from 97 to XP and it uses the...
1
by: barma16 | last post by:
I've hit a bit of a brick wall here, and could use some advice. I have an Access application whose output is a four-tab Excel spreadsheet where three of the four tabs are the result of database...
2
by: Anne Sachleben via AccessMonster.com | last post by:
I am using the TransferSpreadsheet function to export a query result to a specific worksheet in an Excel file titled "report". I want the result to be exported to the worksheet titled "facts". ...
13
by: aleksandra_83 | last post by:
Hello, I have searched all over google groups and internet, but I have not found a solution to this problem that has worked. The solutions I found helped me single out the line that is causing...
2
by: rlntemp-gng | last post by:
re:Access 2003 TransferSpreadsheet has worked in my app for weeks now. Now, the day I was to put in production (today) it crashes the app, and users are livid...but not more than me...
2
by: RZ15 | last post by:
Hi, I am trying to use the transferspreadsheet command to transfer a table into an excel file i have. I'm using the following code: Private Sub cmdOK_Click() 'Run Make-Table query...
5
by: D.Stone | last post by:
I'm getting a problem with importing an Excel spreadsheet into a table in a SQL Server 2000 back-end. I'm doing this in VBA in an onClick event proc in an Access 2003 project. The target table's...
3
by: Icarus | last post by:
I'm using TransferSpreadsheet to import an Excel file in to MS Access 2003. DoCmd.TransferSpreadsheet acImport, 8, strTable, strFileName, True, "" One of the columns in the Excel file is a...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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,...

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.