Hello everyone,
I've been working unsuccessfully on this issue all week, and I've finally raised the white flag...I need some help.
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 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")
[u]
oRng1.Value = Val(txtwrite.Text)</u>
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 a string value entered into the textbox is lost somewhere along the way upon clicking on the command button. The value written to excel is just "0" (the number zero). However, if I enter a number into the textbox, it works just fine. It seems like a data type issue, but I'm not versed enough in
VB to know how to reconcile it.
Another strange finding: if I "hard code" a string, instead of using a text box value (see line of code underlined, bold face above), that also works perfectly. This raises doubts that the problem is a data type issue.
Does anyone know what is happening here?? I'm kind of lost, and would appreciate any help at all!!! thank you very much in advance.
-bri