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

Excel range object into VB.net


I want to place information from an active Excel spreadsheet to a VB.net
form. I just want to place numbers from an Excel cell in a standard
VB.net text box. Does anyone have sample code to demonstrate this
process? I have tried coding the process myself without success. I have
just purchased a 2003 version of VB.net and I am not sure if it is me or
changes in the program. I would like a working example to check my
setup.

Thanks,

Larry Jones
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 21 '05 #1
2 2273
Please forgive my inability to decipher your intent but it is not clear
to me what you are trying to do.

You want to put the contents of one cell or an entire worksheet in a
textbox?

"Larry Jones" <la****@frontiernet.net> wrote in message
news:la****@frontiernet.net:
I want to place information from an active Excel spreadsheet to a VB.net
form. I just want to place numbers from an Excel cell in a standard
VB.net text box. Does anyone have sample code to demonstrate this
process? I have tried coding the process myself without success. I have
just purchased a 2003 version of VB.net and I am not sure if it is me or
changes in the program. I would like a working example to check my
setup.

Thanks,

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


Nov 21 '05 #2
> I want to place information from an active Excel spreadsheet to a VB.net
form. I just want to place numbers from an Excel cell in a standard
VB.net text box. Does anyone have sample code to demonstrate this
process? I have tried coding the process myself without success. I have
just purchased a 2003 version of VB.net and I am not sure if it is me or
changes in the program. I would like a working example to check my
setup.


Can we assume that Excel is also installed on the server? If so, then the
way to
approach this is to use the Excel object library to open the Excel file and
parse it. There's a bit of steep learning curve with Excel but I've done a
lot of Excel VBA work so can help out. This page_load event handler does
something like you're after:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim ExcelApp As New Excel.Application
Dim Workbook As Excel.Workbook =
ExcelApp.Workbooks.Open("c:\scratch\book1.xls")
Dim Worksheet As Excel.Worksheet = Workbook.Sheets(1)
TextBox1.Text = Worksheet.Range("A1").Value
Workbook.Close(False)
ExcelApp.Quit()
End Sub

This does the following:

o Creates an Excel application object
o Opens the c:\scratch\book1.xls
o Finds the first sheet
o Copies the value from cell A1 into the textbox

Along the right lines?

Some issues:

o You'll need Excel installed and therefore a license
o You'll get access denied when you try and creat the Excel app unless the
IIS accounts have the correct access
o How you get the book1.xls uploaded to the server I leave as an exercise
for the reader.

Cheers, Rob.
Nov 21 '05 #3

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

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...
0
by: ImraneA | last post by:
Hi there Many thanks to those people who contributed to this group, helped me greatly. Enclose, my code, hope it helps others :- Public Function Export_Excel_9(tbx1 As Variant, tbx2 As...
2
by: Jean | last post by:
Hi all, I have a problem automating an Excel object from Access. I have the following fucntion that creates a table in Excel from an Access query: Function CreateTable2(strSourceName As...
4
by: IMS.Rushikesh | last post by:
Hi All, I am trying to execute below code but it gives me an COMException ///// Code Start //// public string GetName(Excel.Range range) { try { if (range.Name != null)
22
by: Howard Kaikow | last post by:
There's a significant problem in automating Excel from VB .NET. Reminds me of a problem I encountered almost 3 years ago that was caused by the Norton Auntie Virus Office plug-in. Can anybody...
4
by: goonsquad | last post by:
I'm writing an Excel Automation app and I'm running to a problem early on with what should be a basic step. Dim oExcel As Object Dim oBook As Object Dim oSheet As Object Dim oRng As...
3
by: | last post by:
I wrote a class in VB.NET to export the contents of a datagrid to Excel. It works perfectly on my machine, but it fails on my customers' PCs that have identical versions of Win XP (SP1) and Excel...
7
by: Alan Roberts | last post by:
Can someone please explain the following for me... I am trying to link to a .NET DLL from Excel. Excel needs to pass a reference to itself to the DLL and then the DLL needs to perform some work...
18
by: Frank M. Walter | last post by:
Hello, I have made an small AddIn with udf for excel 2003. I use vs2003. The point of view is the function __T() I call it in excel sheet writing =__T() I am not able to set a value to a...
16
by: alexia.bee | last post by:
Hi all, In some weird reason, excel instance won;t die if i remove the comment from 4 lines of setting values into struct. here is a snipcode public...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: 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:
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: 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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.