How do I make vb 2005 read and write to a specified cell in excell 2003 & 2007.
5 2337
How do I make vb 2005 read and write to a specified cell in excell 2003 & 2007.
have you searched around the forum? there are many examples of that. You can use an object with an excel application: -
dim obj1 as object
-
dim a as variant 'or object, i dont remember how it's defined in vb2005
-
dim b as string
-
set obj1 = createobject("excel.application") 'I think "set" is not used in vb 2005, so it'll remove it.
-
obj1.workbooks.open "c:\mybook.xls"
-
obj1.cells(1,1) = "hello":obj1.cells(1,2) = "goodbye"
-
with obj1.worksheets(1)
-
a=range(.cells(1,1), .cells(1,1).end(-4121)) '-4121 is the number of the constant xldown, but it's not recognized by all the versions of vb, so -4121 or -4161 for xlleft will help.
-
b=.cells(1,1).value
-
end with
you might have some troubles while closing the application, so what i'll recomend you to do, in order to avoid generating trash is to make it visible before you close it: - obj1.visible=true
-
ob1.quit 'or was it close instead of quit? i'll have to check that out.
HTH
Note: when you use obj1.cells(y,x) it'll asume you're using the "activebook" and "activesheet" the "right complete way" would be obj1.workbooks(1).worksheets(1).cells(1,1). Same for obj1.worksheets(1), it'll asume the workbook
Thanks for the help
With obj1.worksheets(1)
a = range(.cells(1, 1), .cells(1, 1).end(-4121)) '-4121 is the number of the constant xldown, but it's not recognized by all the versions of vb, so -4121 or -4161 for xlleft will help.
b = .cells(1, 1).value
End With
I get a message saying range is not declared.
I took range out and it works fine. Can you tell me how to read a cell now
this is how I read txt files
fileReader =
My.Computer.FileSystem.ReadAllText("C:\test.txt")
do i need to change the read all?
I took range out and it works fine. Can you tell me how to read a cell now
this is how I read txt files
fileReader =
My.Computer.FileSystem.ReadAllText("C:\test.txt")
do i need to change the read all?
the second example reads only a cell - dim b as string
-
b= obj1.cells(1,1)
while working with text files, i'd supose you want to read a tabs separated file. so the easiest way will be to save the file the way you're doing it, and then with the MID and INSTR functions take the "cell" you want. -
fileReader=my.computer.filesystem.readalltext("c:\test.txt")
-
fileReader=mid(fileReader,1,instr(fileReader,chr(9))-1)
will give you the "first cell" of a tabs separated textfile
HTH
Thanks for the help
With obj1.worksheets(1)
a = range(.cells(1, 1), .cells(1, 1).end(-4121)) '-4121 is the number of the constant xldown, but it's not recognized by all the versions of vb, so -4121 or -4161 for xlleft will help.
b = .cells(1, 1).value
End With
I get a message saying range is not declared.
I see, i think it's because range is a VBA function, try with
a= obj1.range(.cells(1,1) ...
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Paul |
last post by:
I was wondering if anyone has had an issue where using vba code to
read an excel file and import the data into an access table some
records are not imported from the excel file. It seems looking at...
|
by: mail2atulmehta |
last post by:
Hi,
I do not know if this is right place for this, but i need some help. I
have a text file, whose values are seprated by a delimiter. I want to
open this file in excel, ( not import it) . I have...
|
by: Jon Brookins |
last post by:
I'm reposting this question as the other post seems to have been
sucked into the net black hole.
I'll keep this short. I am trying to read and edit an Excel workbook
in its native BIFF format. ...
|
by: Rashrashetta |
last post by:
Hai all,
I am trying to read and write to an excel sheet using C# in a
webform...
I'v read alot of tutorials and used it...it works BUT ONLY
ONCE...Especially when writing to the sheet...
I...
|
by: Scott M. Lyon |
last post by:
I've just discovered a bug in some code I wrote a little while ago, and I
need you guys' help to fix it.
My program imports data from a standard Excel Spreadsheet (just with
specific column...
|
by: nuti |
last post by:
Hi all,
I am fairly new to VB.I am trying to figure out as how to write a
script so that i can read the data from an excel sheet to Access.
can u guys please help me out?
cheers,
nuti
|
by: RJN |
last post by:
Hi
I've a template excel file which has all the calculations defined. There
are certain input values to be entered which gives a lot of output to
the user. I don't want to expose the excel sheet...
|
by: dba123 |
last post by:
I need some help and direction on what classes and an example or two
(article) on how to read an Excel Worksheet and insert one column into a
database table column. I am using .NET 2.0 only. What...
|
by: i.arda.tezcan |
last post by:
Hello,
I'm trying to make a web page that will read the xls file and make a
table out of it on the web page. I want to change the excel file from
time to time and I want the changes to be...
|
by: Tony Bansten |
last post by:
As fas as I heard I can write to Excel cell e.g. E53 from outside with VBS.
How could such a code look like?
Assume I have an Excel file aaa.xls and a worksheet "ws777" inside:
How can I wread...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
| |