hi!
how can we take textbox data from a visual basic 6.0 form and write it to an excel worksheet once a command button is clicked?
I've gotten very close to completing this on my own, here is my code:
Private Sub cmdwrite_Click()
Dim oExcel As Excel.Application
Dim oWB As Excel.Workbook
Dim oWS As Excel.Worksheet
Set oExcel = New Excel.Application
oExcel.Visible = True
Dim oRng1 As Excel.Range
Dim oRng2 As Excel.Range
Set oWB = oExcel.Workbooks.Add
Set oWS = oWB.Worksheets("Sheet1")
Set oRng1 = oWS.Range("A1")
oRng1.Value = Val(txtwrite.Text)
oWB.SaveAs ("writeit.xls")
Cleanup:
Set oWS = Nothing
If Not oWB Is Nothing Then oWB.Close
Set oWB = Nothing
oExcel.Quit
Set oExcel = Nothing
End Sub
Private Sub cmdquit_click()
End
End Sub
the problem I am having, is that the value entered in the textbox is lost somewhere along the way, and the value written to excel is just "0" (the number zero).
what is happening there?? I'm kind of lost, and would appreciate any help at all!!! thank you very much in advance.
-bri
4 5325
hi!
the problem I am having, is that the value entered in the textbox is lost somewhere along the way, and the value written to excel is just "0" (the number zero).
what is happening there?? I'm kind of lost, and would appreciate any help at all!!! thank you very much in advance.
-bri
Well, i think it's because you're using Val(textbox.text). If for some reason the text in the textbox doesn't start with a number, its value will be zero.
e.g.
Val("h33") is zero
Val("33a234") is 33
HTH
Well, i think it's because you're using Val(textbox.text). If for some reason the text in the textbox doesn't start with a number, its value will be zero.
e.g.
Val("h33") is zero
Val("33a234") is 33
HTH
OK! Thanks for the reply! : )
I guess it is safe to assume that the Val( ) function is only for numbers then? Is there a more generic function I can use that would work regardless if it is a number of a string of characters?
I appreciate your help,
Brian
OK! Thanks for the reply! : )
I guess it is safe to assume that the Val( ) function is only for numbers then? Is there a more generic function I can use that would work regardless if it is a number of a string of characters?
I appreciate your help,
Brian
hmm, what do you want it for?. If you want it to show the variable, just write it, without any function. Val works with both, strings and numbers, but if your string does not start with a number, its value will be zero.
sorry, nevermind.
I had a typo syntax error and it's working perfectly. Thanks again for your help!
-b
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Kurien Baker Fenn |
last post by:
How to send data from an ASP form to a visual basic form?
Please help
|
by: evlpupy |
last post by:
Good Afternoon
I have need of assistance for programming a visual basic form in excel.
In excel I have 3 named ranges
TM
Agents1
Agents2
In the TM range I have 5 different names of...
|
by: trezraven |
last post by:
I am creating a template in Word 2007 using Visual Basic Editor. I am pulling information from an Access database. I know this is probably a stupid question, but for the life of me I can't figure out...
|
by: rayne |
last post by:
hi pls help me on how to play a video in full screen using visual basic 6 and how can I unload the screen and load another form after the video stop from playing.
Another is how can I save a video...
|
by: Edward1 |
last post by:
Hi! I am a newbie to programming, I am tryin to build a database application using visual basic .net and Ms Access, right now I am unable to update the Ms Access Database from visual basic. can...
|
by: Galore |
last post by:
Hi All,
I am a new member.
I am trying to run a query (e.g. select * from SybaseTable where SybaseCol = '12') directly from Excel.
I am hoping to be able to define the Data Source (define...
|
by: suresh_punniyakkodi |
last post by:
Hellow Friends,
I have one doubt, please help me...
In Excel, i have lot of rows and coloumns, i need to read all cell values with in rows and coloumn limit...
At the time...
|
by: Johnny Wong |
last post by:
Hi, I am new to visual basic.
In my vb system, there is a dynamic datagrid to represent different reocrds in our database. Today I am gonna export the data to Excel file. I found most examples code...
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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$) {
}
...
|
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...
|
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...
|
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...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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: 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,...
| |