Click to See Complete Forum and Search --> : Combing Excel files with VB. URGENT!!!
New VB
September 19th, 2001, 03:35 AM
hey people im a newbie at VB programing and am requiring some help with a school project
what i am requesting is that i need help with coding to be able add data from a form to an excel file. and also to be able to view excel files
Thanks for any Help
Iouri
September 19th, 2001, 07:05 AM
Here is an example how to write to excel
Set oExcel = GetObject(App.Path & "\my.xls")
oExcel.ActiveSheet.Range("A1").Value = "My Data"
oExcel.ActiveSheet.Range("B2").Value = "MyData"
oExcel.ActiveSheet.Range("C2").Value = "Value"
oExcel.Application.Visible = True'this line will bring Excel to the top
oExcel.Parent.Windows(1).Visible = True
Set oExcel = Nothing ' Remove object variable.
Iouri Boutchkine
iouri@hotsheet.com
Cimperiali
September 19th, 2001, 07:36 AM
'another example, with early binding
'most of this code was included in a question about excel
'and cells formats here in Codeguru
option Explicit
'reference to:
'microsoft excel 9.0 object lybrary
private withevents xlApp as Excel.Application
private withevents xlBook as Excel.Workbook
private withevents xlSheet as Excel.Worksheet
Dim Quitted as Boolean
private Sub Command1_Click()
If xlApp is nothing then
set xlApp = new Excel.Application
End If
xlApp.Workbooks.Add
If xlBook is nothing then
set xlBook = xlApp.Workbooks(1)
End If
xlApp.Visible = true
End Sub
private Sub Command2_Click()
If Not xlApp.ActiveWorkbook is nothing then
If xlApp.Worksheets.Count = 0 then
set xlSheet = xlApp.Worksheets.Add
else
set xlSheet = xlApp.Worksheets(1)
End If
else
xlApp.Workbooks.Add
set xlSheet = xlApp.Worksheets.Add
End If
xlSheet.Range("A1").Value = "bla"
xlSheet.Range("A1").Font.Bold = true
xlSheet.Columns("A:A").ColumnWidth = 17.43
xlSheet.Rows("1:1").RowHeight = 15
xlSheet.Range("A3").Select
With xlApp.Selection.Interior
.ColorIndex = 6
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
End With
End Sub
private Sub xlApp_WorkbookBeforeSave(byval Wb as Excel.Workbook, byval SaveAsUI as Boolean, Cancel as Boolean)
xlApp.DefaultFilePath
End Sub
private Sub xlBook_BeforeClose(Cancel as Boolean)
Quitted = true
End Sub
Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, TCartwright, Bruno Paris, Dr_Micahel
and all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.
The Rater
New VB
September 20th, 2001, 03:51 AM
Thanks people for the coding supplied it should help me alot
if you have any other sample coding that might be of some help it would be much appriciated
thanks again
New VB
Cimperiali
September 20th, 2001, 05:28 AM
see on the page
Forum Index|FAQ|Edit Profile|Send Private|...|Search|...
These are links. Click on
|Search|
and type in "Excel" (without quotes) as searched word. You will find a lot of code.
Have a nice day,
Cesare Imperiali
Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, TCartwright, Bruno Paris, Dr_Micahel
and all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.
The Rater
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.