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.Applicati on
Dim oWB As Excel.Workbook
Dim oWS As Excel.Worksheet
Set oExcel = New Excel.Applicati on
oExcel.Visible = True
Dim oRng1 As Excel.Range
Dim oRng2 As Excel.Range
Set oWB = oExcel.Workbook s.Add
Set oWS = oWB.Worksheets( "Sheet1")
Set oRng1 = oWS.Range("A1")
oRng1.Value = Val(txtwrite.Te xt)
oWB.SaveAs ("writeit.xl s")
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
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.Applicati on
Dim oWB As Excel.Workbook
Dim oWS As Excel.Worksheet
Set oExcel = New Excel.Applicati on
oExcel.Visible = True
Dim oRng1 As Excel.Range
Dim oRng2 As Excel.Range
Set oWB = oExcel.Workbook s.Add
Set oWS = oWB.Worksheets( "Sheet1")
Set oRng1 = oWS.Range("A1")
oRng1.Value = Val(txtwrite.Te xt)
oWB.SaveAs ("writeit.xl s")
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
Comment