
Excel to VB and VB to Excel
Here you are:
Option Explicit
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Private Sub Command1_Click()
' These lines move data from VB to Excel
xlSheet.Cells(1, 1).Value = Text1.Text
xlSheet.Cells(2, 1).Value = Text2.Text
xlSheet.Cells(3, 1).Value = Text3.Text
' The next line fetches data from Excel into VB
Text4.Text = Format(CCur(Abs(xlSheet.Cells(4, 1).Value)), "##,###.00")
End Sub
Private Sub Command2_Click()
Unload Me
End Sub
Private Sub Form_Load()
Set xlApp = New Excel.Application
Set xlBook = GetObject("c:\temp\book1.xls")
Set xlSheet = xlBook.Worksheets("Sheet1")
End Sub
Private Sub Form_Unload(Cancel As Integer)
xlBook.Close False
xlApp.Quit
Set xlApp = Nothing
End Sub
Eric
Quote:
> Hi !
> I have an idea to let excel make some calculations for me
> (its easyer for me to make formels in excel) i.e.
> i put a number in a textbox in vb this number goes to
> execel in a ark i.e cell A25. Excel makes the calc. and the
> result is in i.e cell G34, this result shut go back to vb
> in a textbox.
> Is there sombody who can and will help me ????
> Thanks.
> * Sent from AltaVista http://www.altavista.com Where you can also find
related Web Pages, Images, Audios, Videos, News, and Shopping. Smart is
Beautiful