473,834 Members | 1,874 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

VB.Net MS Excel Question

I have a question...I am attempting to write the values of multiple textboxes to an MS Excel spreadsheet. I would like to be able to write the values to let say a1,b1,c1,d1...e ct and then click on a button to write new values to the next row a2,b2,c2,d1...e ct...This is what I came up with but it does not do what I need it to do. here is what I am missing.

a.. I would rather write values to a prexisting MS Excell sheet ex "C:/temp/textexcell.xls"
b.. when I click on the next button it would use either the code I have or something to prepare the user to write values to the next row.
Thanks in advance for your help!!!
Public Class Form1

Inherits System.Windows. Forms.Form

Dim alpha As Char

Dim beta As Char

Dim charlie As Char

Dim num As Integer

Dim a As String

Dim b As String

Dim c As String

Dim exsell As New Excel.Applicati on

Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles Button1.Click

num = 1

alpha = "a"

beta = "b"

Charlie ="c"

a = Convert.ToStrin g(alpha & num)

b = Convert.ToStrin g(beta & num)

c = Convert.ToStrin g(Charlie & num)

Dim exsell As New Excel.Applicati on
exsell.Visible = True

exsell.Workbook s.Add()

exsell.Range(a) .Select()

exsell.ActiveCe ll.FormulaR1C1 = TextBox1.Text

exsell.Range(b) .Select()

exsell.ActiveCe ll.FormulaR1C1 = TextBox2.Text

textbox1.text =""

textbox2.text =""

textbox3.text =""



End Sub

'Private Sub btnNextRow_Clic k(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles Button2.Click

' num = num + 1

' alpha = "a"

' beta = "b"

' Charlie ="c"

' a = Convert.ToStrin g(alpha & num)

' b = Convert.ToStrin g(beta & num)

' c = Convert.ToStrin g(charlie & num)

exsell.Range(a) .Select()

exsell.ActiveCe ll.FormulaR1C1 = TextBox1.Text

exsell.Range(b) .Select()

exsell.ActiveCe ll.FormulaR1C1 = TextBox2.Text

' exsell.Range(c) .Select()

' exsell.ActiveCe ll.FormulaR1C1 = TextBox3.Text

'End Sub
--
SHANE CLARK

Dec 14 '05 #1
1 3108
First, you'll be spamming your users with Excel apps everytime they click
button1 :). Fix that first. Next change exsell.Workbook s.Add() to
exsell.Workbook s.Open("C:/temp/textexcell.xls" ) Without testing it, I'd say
that calling it again when it's open should just pop it to the front, but
check that to be sure.

Do you have a definate number of colums? because plotting by letter & number
is really only useful for very few cells, after that you might want to locate
cells by addressing Cells(row,colum n) This should act just like a range
object and allow you to select individual cells. You can either keep track
of the rows in particular to a single user, or search down for the next empty
row and keeping a RowIndex in the scope of your class. Everytime a row is
filled: RowIndex =+1 and call your columns.
cells(RowIndex, 1),cells(RowInd ex,2) for each colum you want. I'm guessing to
the number of text boxes you have.

Randy

"SHANE CLARK" wrote:
I have a question...I am attempting to write the values of multiple textboxes to an MS Excel spreadsheet. I would like to be able to write the values to let say a1,b1,c1,d1...e ct and then click on a button to write new values to the next row a2,b2,c2,d1...e ct...This is what I came up with but it does not do what I need it to do. here is what I am missing.

a.. I would rather write values to a prexisting MS Excell sheet ex "C:/temp/textexcell.xls"
b.. when I click on the next button it would use either the code I have or something to prepare the user to write values to the next row.
Thanks in advance for your help!!!
Public Class Form1

Inherits System.Windows. Forms.Form

Dim alpha As Char

Dim beta As Char

Dim charlie As Char

Dim num As Integer

Dim a As String

Dim b As String

Dim c As String

Dim exsell As New Excel.Applicati on

Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles Button1.Click

num = 1

alpha = "a"

beta = "b"

Charlie ="c"

a = Convert.ToStrin g(alpha & num)

b = Convert.ToStrin g(beta & num)

c = Convert.ToStrin g(Charlie & num)

Dim exsell As New Excel.Applicati on
exsell.Visible = True

exsell.Workbook s.Add()

exsell.Range(a) .Select()

exsell.ActiveCe ll.FormulaR1C1 = TextBox1.Text

exsell.Range(b) .Select()

exsell.ActiveCe ll.FormulaR1C1 = TextBox2.Text

textbox1.text =""

textbox2.text =""

textbox3.text =""



End Sub

'Private Sub btnNextRow_Clic k(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles Button2.Click

' num = num + 1

' alpha = "a"

' beta = "b"

' Charlie ="c"

' a = Convert.ToStrin g(alpha & num)

' b = Convert.ToStrin g(beta & num)

' c = Convert.ToStrin g(charlie & num)

exsell.Range(a) .Select()

exsell.ActiveCe ll.FormulaR1C1 = TextBox1.Text

exsell.Range(b) .Select()

exsell.ActiveCe ll.FormulaR1C1 = TextBox2.Text

' exsell.Range(c) .Select()

' exsell.ActiveCe ll.FormulaR1C1 = TextBox3.Text

'End Sub
--
SHANE CLARK

Dec 14 '05 #2

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

Similar topics

12
22952
by: jimserac | last post by:
I had previously posted this in an Access forum with negative results so will try here. Although this question specifies an Access database, I also wish to accomplish this with a large MS SQL Server database that we have. Question follows: The following SQL statement, used in VBScript,
6
18577
by: Sam Johnson | last post by:
HI I tried to send the following SQL string to an open databse, to export a table into excel format: g.Connection = conn 'valid OleDBConnection and Command objects g.CommandText = "SELECT * INTO XLSTest IN 'C:\' 'Excel 8.0;' FROM Table1" g.ExecuteNonQuery()
3
8903
by: George | last post by:
Sub ExcelToListBox() Dim xRange As Object Dim ary Dim xValue As String xRange = oXL.Range("A1:A9") 'has letters A-H ary = xRange.value xValue = ary(3, 1) 'xValue = C Me.ListBoxPerson.Items.AddRange(ary)
19
12774
by: wreckingcru | last post by:
I'm trying to output a SQL query that is constructed thru my VB.net GUI into an excel file. Here is the code I'm using: 'Sqlstmt is the SQL query statement 'Conn is the SQL Connection object cmd = New SqlCommand(Sqlstmt, Conn) datareader = cmd.ExecuteReader()
2
3127
by: Mad Scientist Jr | last post by:
>From an asp.net web page I want the user to open the results of a SQL query in Excel, as automatically as possible (ie not having to loop through columns, rows, in code). For this, dataset.writexml works great (got the code from http://forums.devx.com/archive/index.php/t-57273.html ) The only question I have is, when Excel opens up, it isn't the view I would prefer. It opens as a read-only workbook, I would prefer as an
6
2074
by: Gunawan | last post by:
Dear All, I have create an excel (COM Object) using this code Excel.Application xls = new Excel.Application(); but I can not remove it from memory although I have using close and quit wb.Close(false, false, 0); xls.Quit();
9
4556
by: Doug Glancy | last post by:
I got the following code from Francesco Balena's site, for disposing of Com objects: Sub SetNothing(Of T)(ByRef obj As T) ' Dispose of the object if possible If obj IsNot Nothing AndAlso TypeOf obj Is IDisposable Then DirectCast(obj, IDisposable).Dispose()
7
7089
by: ddecoste | last post by:
I have a need to add a visual representation to some data in Access. I need to draw a matix of squares inside another square. I have all the data that I need in a record in Access. The data changes according to what the user inputs. I know that Access does not allow you to draw on forms so I decided to put the output in an Excel file for the user but I am having trouble drawing the rectange from Access. Here is my simple code so far: ...
3
4853
by: pleaseexplaintome_2 | last post by:
using the code below (some parts not included), I create a new excel workbook with spreadheets. I then want to delete a spreadsheet, but a reference remains open and excel stays in task manager when the code highlighted below is used. can someone help me identify what object remains open and how to release that reference? thanks using Excel = Microsoft.Office.Interop.Excel;
3
7392
by: akristensen | last post by:
I am new to this site, so be patient if I do not ask the question correctly. Current Target Platform: Browser: MS IE, script language: Javascript (will use VBScript, but JS is preferred), External apps: MS Excel What I need to do: From a web page using javascript, I open a new Excel application and sheet, populate some information into it. After it is populated with some information, I need to run the "Solver..." option on the data in the...
0
9646
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,...
0
10793
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10548
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,...
1
7758
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6954
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5627
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...
0
5794
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4427
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3081
bsmnconsultancy
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...

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.