Welcome to Dream.In.Code
Getting VB Help is Easy!

Join 136,324 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 2,789 people online right now. Registration is fast and FREE... Join Now!




Excel in VB6.0

 
Reply to this topicStart new topic

Excel in VB6.0

georgewba
1 Sep, 2008 - 05:53 PM
Post #1

New D.I.C Head
*

Joined: 4 Jul, 2008
Posts: 6


My Contributions
This is the code for creating an excel workbook and excel worksheets and how to write anything in the sheet :
First, Excel object library must be refernced, then write this code :
CODE

Dim objExcel as Excel.Application
Set objExcel = New Excel.Application
objExcel.Visible = True
ObjExcel.SheetsInNewWorkbook = 1
ObjExcel.Workbooks.Add

This is the code for crearting an excel workbook and excel worksheets . In this part we create an excel workbook. we set how many worksheets we want in the workbook in the forth line.

The following code is for writing in the active worksheet :
CODE

with objExcel.ActiveSheet
      .Cells(1, 2).Value = "10"
      .Cells(2, 2).Value = "20"
      .Cells(3, 2).Value = "SUM(B1:B2)"
      .Range("A3")= "Total"
End With

In this part we write in the active worksheet what we want. We refer to the cell with two methods :
1. The first method by writing :
CODE

objExcel.ActiveSheet.Cells(1, 2).Value = The Text or the Formula we want , like that in Line4 in the previous example, we want to write

That is like the code in the previous example. We refer to the cell by writing the syntax like that :
CODE

objExcel.ActiveSheet.Cells([b][i]The number of the Row[/i][/b],[b][i] The number of the Column[/i][/b]).Value = The Text we want to write


2. The second by writing :
CODE

objExcel.ActiveSheet.Range("A3") = The Text we want to write

This is like the code in the previous example. we refer to the cell by writing the syntax like that :
CODE

objExcel.ActiveSheet.Range([b][i]The Name of the Cell in the Excel WorkSheet[/i][/b]) = The Text we want to write

But I don't know if whether we can write a Formula in the Cell by this syntax or not.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 07:35AM

Live VB Help!

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month