473,491 Members | 1,917 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Controlling Excel from Access

I have to perform an import from an excel file to Access. The file
comes originally as a csv file. I have to delete some rows and
columns, then change the formatting of some columns. I am using
Windows 2000, Office 2000

I have been able to do everything but fill a column with zeros

Here is some of the code attached to a command button, I am using, it
works except I can't figure out how to fill down one column. In excel
it uses the Selection.FillDown command but I can't find that in the
Excel Reference in Access. Any other ideas.

with xlssheet
.Columns("E:E").Insert
.Range("E1").FormulaR1C1 = "Free Credit"
.Range("e2").FormulaR1C1 = "0"
this is where I will insert modified code.
end with

Essentially, I want to copy cell E2 to the last row in this column.
This is what I use in Excel that works, how can it be translated into
Access?? Selection doesn't seem to be an available option in Access
nor does ActiveCell appear.
range("A1").select
Selection.End(xlDown).Select
lastrow = ActiveCell.Row
Range("e2:e" & lastrow).Select
Selection.FillDown

Once this is done the file is then saved in an Excel format and closed
and then imported into Access.

Thanks for your help
Nov 13 '05 #1
3 11200
Hi Lynn,
Instead of doing the following

range("A1").select
Selection.End(xlDown).Select
lastrow = ActiveCell.Row
Range("e2:e" & lastrow).Select
Selection.FillDown

you can do this:

lastrow = range("A1").End(xlDown).Row

all in one line. You can't use Select from Access. That only works in
the Excel User Interface. Then you can do this (assumes you have a
reference to the Excel Object Library in Tools/References from a code
module):

Dim xlObj As Excel.Application, wkbk As Excel.Workbook
Dim sht As Excel.WorkSheet
Set xlObj = CreateObject("Excel.Application")
Set wkbk = xlObj.Workbooks.Open("youExcelFile.xls")
set sht = wkbk.Sheets("Sheet1")
...
lastrow = sht.range("A1").End(xlDown).Row
...
sht.range("e2:e" & lastrow).FillDown

Note: I have found that using CreateObject (or GetObject)
("Excel.Application") works better than

Dim xlObj As New Excel.Application

Even in VB.Net and C#, createObject is alive and well.

Rich

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 13 '05 #2
Thank so much Rich,

This is exactly what I was looking for, I just wasn't finding it.

Lynn
Rich P <rp*****@aol.com> wrote in message news:<41**********************@news.newsgroups.ws> ...
Hi Lynn,
Instead of doing the following

range("A1").select
Selection.End(xlDown).Select
lastrow = ActiveCell.Row
Range("e2:e" & lastrow).Select
Selection.FillDown

you can do this:

lastrow = range("A1").End(xlDown).Row

all in one line. You can't use Select from Access. That only works in
the Excel User Interface. Then you can do this (assumes you have a
reference to the Excel Object Library in Tools/References from a code
module):

Dim xlObj As Excel.Application, wkbk As Excel.Workbook
Dim sht As Excel.WorkSheet
Set xlObj = CreateObject("Excel.Application")
Set wkbk = xlObj.Workbooks.Open("youExcelFile.xls")
set sht = wkbk.Sheets("Sheet1")
..
lastrow = sht.range("A1").End(xlDown).Row
..
sht.range("e2:e" & lastrow).FillDown

Note: I have found that using CreateObject (or GetObject)
("Excel.Application") works better than

Dim xlObj As New Excel.Application

Even in VB.Net and C#, createObject is alive and well.

Rich

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 13 '05 #3

Dear Lynn

thank you for posting the bit of code.
It was exactly the clue I was looking for

I was trying to insert a blank row into Excel from Vis Basic
or Acess.

John Fox

Lynn A. wrote:
I have to perform an import from an excel file to Access. The file
comes originally as a csv file. I have to delete some rows and
columns, then change the formatting of some columns. I am using
Windows 2000, Office 2000

I have been able to do everything but fill a column with zeros

Here is some of the code attached to a command button, I am using, it
works except I can't figure out how to fill down one column. In excel
it uses the Selection.FillDown command but I can't find that in the
Excel Reference in Access. Any other ideas.

with xlssheet
.Columns("E:E").Insert
.Range("E1").FormulaR1C1 = "Free Credit"
.Range("e2").FormulaR1C1 = "0"
this is where I will insert modified code.
end with

Essentially, I want to copy cell E2 to the last row in this column.
This is what I use in Excel that works, how can it be translated into
Access?? Selection doesn't seem to be an available option in Access
nor does ActiveCell appear.
range("A1").select
Selection.End(xlDown).Select
lastrow = ActiveCell.Row
Range("e2:e" & lastrow).Select
Selection.FillDown

Once this is done the file is then saved in an Excel format and closed
and then imported into Access.

Thanks for your help


Nov 13 '05 #4

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

Similar topics

0
2820
by: Jack | last post by:
Windows 2K Pro Access/Excel 2003 Hi there, I have a large number of password protected Excel Workbooks. The files are protected by code that runs when the workbook opens. The code asks the...
1
4610
by: Aiysha | last post by:
Hi, I want to take cotrol of notepad from excel (through VB programming). I have .prn files which have to opened in notepad and then I have to save these .prn files in .sim , all files format. ...
8
1689
by: Charley Kyd | last post by:
I'd like to learn how to use VS.NET as though it were Excel VBA, with the goal of creating a compiled Excel addin. That is, I'd like... ....all forms to belong to the Excel environment. ....the...
0
1663
by: Al Christians | last post by:
I'm starting to test a python application that creates an Excel workbook, then fills in values for some cells and formulas for other cells. The formulas involve circular references, which will...
8
2163
by: GaryDean | last post by:
We have been noticing that questions on vs.2005/2.0 don't appear to get much in answers so I'm reposting some questions posted by some of the programmers here in our organization that never got...
3
5046
by: Tim Marsden | last post by:
Hi, I am currently creating an instance of Excel using VB.NET Automation. dim xl as Excel.Application xl = new Excel.Application However, how can I have more control over the starting of...
1
1754
Walt in Decatur
by: Walt in Decatur | last post by:
Is there a way to control Access charts to the degree that can be done in Excel? Specifically, I would like to be able to define colors and use the DLookUp function to define the input for the axis...
16
5149
by: Phil Stanton | last post by:
I have a form with a button which is supposed to open an Excel file (With lots of Macros /VBA) in it. The Excel file gets it's data from the Access program Here is the code Private Sub...
1
1602
by: rweston | last post by:
I am trying to open an MS Excel file and perform a find/replace function, all using VBA within MS Access. I keep getting a "Subscript out of range." error. Do you know why I am getting this error? ...
0
7118
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
6980
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
7157
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
7192
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...
1
6862
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...
0
7364
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
5452
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,...
1
4886
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...
0
3087
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...

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.