I have a spreadsheet with about 35 tabs that I need to import into one table in Access. I found this link http://www.thescripts.com/forum/thre...iple+tabs.html and changed some things within the code.
First off - I've written a piece of code that changes the name of each sheet (Sheet1, Sheet2, etc), deletes the blank rows and formats a couple of the columns to text and date format. It then saves and quits the application as well as sets it to nothing.
When I try to run the code that is within the above link I get
*RunTime Error '91' Object variable or With block variable not set*
Here's the code: - Dim excelapp As New Excel.Application
-
Dim excelbook As New Excel.Workbook
-
Dim excelsheet As New Excel.Worksheet
-
Dim intNoOfSheets As Integer, intCounter As Integer
-
Dim strFilePath As String, strLastDataColumn As String
-
Dim strLastDataRow As String, strLastDataCell As String
-
-
strFilePath = "\\drivemapping\spreadsheet.xls"
-
-
Set excelbook = excelapp.Workbooks.Open(strFilePath)
-
-
intNoOfSheets = excelbook.Worksheets.Count <--It finds 35 sheets
-
-
For intCounter = 3 To intNoOfSheets 'start at sheet 3
-
excelbook.Worksheets(intCounter).Activate
-
'The next 3 lines will obtain the last data cell reference for each Worksheet
-
strLastDataColumn = Chr(Selection.SpecialCells(xlLastCell).Column + 64) <--RUNTIME ERROR '91' HERE
-
strLastDataRow = Selection.SpecialCells(xlLastCell).Row
-
If strLastDataRow = 1 Then 'sheet has no rows to import
-
GoTo Line1
-
End If
-
strLastDataCell = strLastDataColumn & strLastDataRow
-
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel11, "tmp", strFilePath, False, _
-
excelbook.Worksheets(intCounter).Name & "!A2:" & strLastDataCell 'A1 is header row so start on A2
-
Line1:
-
Next
-
-
excelbook.Close
-
excelapp.Quit
-
Set excelapp = Nothing
However...it doesn't do it ALL the time. I just got the error...ended it and then re-ran and it worked fine. I'm using Access 2003 on WinXP SP2. Just want it to be as stable as it possibly can be before I turn it over to the user.
I looked up the error message here & on google but none of the explanations really applied to my scenario. Any help is much appreciated.
1 10916 FishVal 2,653
Recognized Expert Specialist
Hi, there.
Try to refer Selection object through Excel.Applicati on object.
e.g.
instead
Selection.blabl abla
excelapp.Select ion.blablabla
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: sunilkeswani |
last post by:
I need help with exporting data from 2 access tables, into 2 existing
spreadsheets in a single Excel file.
Currently, I am using this code:
DoCmd.TransferSpreadsheet acExport, 8, "Table1", "D:\Test.xls", True
|
by: Nick M |
last post by:
Hello All,
Excellent info here Thanks!
I am very new to using access in general and I am on a learning curve.
I'm trying to import an excel workbook (with worksheets) into an access db
via a macro. (I'll get to using VB later on).
What I would like to do is import a single workbook w/three seperate
worksheets into three seperate access tables AND truncate the time stamp
that is used in the excell sheet via a macro.
|
by: Niklas |
last post by:
Hi
Before I start coding I need to be sure that nobody else has not done it yet
and that I can use it.
I need an import utility which import data from Excel to a database or some
object in .NET. The data in Excel is not in structured columns but can exist
everywhere in the workbook. For example if I am supposed to import a person
and all his/her cars which exist in a workbook I want to be able to create an
import protocol and specify...
|
by: madeleine |
last post by:
I'm hoping the answer to this is that I'm just doing something silly,
but I'm really scratching my head over this one. I'm importing data
from multiple workbooks, each workbook has a sheet called SubSAT and I
need to get specific data from that into the database.
I'm finding that if I have the workbook open on my desktop then the
SubSAT % complete and the High level plan % come in fine, but as soon
as the workbook is closed they come...
|
by: FireGeek |
last post by:
I have a database that is split appropriately. Annually, we need to
add data from .xls files. I have added code so with a click of a
button, it will import this data as a new table into the database. The
problem is that the code is on the front end and thus it imports the
data/new table into the front ent.
How can I accomplish an import (with the click of a button) into the
back end and link it to the front end?
THANKS
| |
by: nehashri |
last post by:
hello
i have my data stored in different Ms Excell sheets. now I am planning to make a database of the data i have. but i m confused whether to use Postgresql or mySQL for the same. i had plans to import data directly to Ms Access but there is problem with my access for now so i have to think of other choises.
i wanted to know whether it is easy to convert excel sheets to postgre that is can i import excel to postgreSQL. if yes how can i go...
|
by: Roy |
last post by:
Hi All,
I have an A2003 application .Recently we had a request to import data
from IDL files and create some reports.
Since I have no idea to do that using Access,I used Excel to import
data and then imported these excel sheets into Access tables.
Is there a way to directly import IDL files into Access using any
method or VBA?
Thanks,
|
by: Harshe |
last post by:
hello all,
I am trying to code, but i am just stuck after importing one sheet. so here is the gist of what i need help with.
In a workbook at the start of the year (january) i will have 4 sheets and these sheets will keep increasing to 12 when the month is december. so i want is, sheet 1 (named abc) should go into table 1 (named abc), sheet 2 (named def)should go into table 2 (named def), sheet 3 (named xyz) should go into table 3 (named...
|
by: ivancycheng |
last post by:
I have around 400 excel files with same format (multiple sheets) and wants to import few sheets from excel to MS Access (XP version) for further processing. any one can advise me how to do it? (I'm very new in using VB). Many Thanks!
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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,...
| |
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...
|
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,...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |