Logo 
Search:

MS Office Forum

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds

What "Set" do in this program? What can I use it for in the VB?

  Asked By: Seth    Date: Oct 25    Category: MS Office    Views: 970
  

I have been studying the following vb code which turn the outcome in
excel for a while, but still can't find the answer.


I have some questions about syntax used in this code.

1. What "Set" do in this program? What can I use it for in the VB?
2. same as above question with "createobject"
3. same as above question with "Resize"
4. oChart.SetSourceData Source:=oSheet.Range("A1").Resize
(cNumRows, cNumCols)
from this statement, what is the meaning of this statement? Please
explain the duty of each component if it possible
5. What is the meaning of this statement? please explain the duty of
each component if it possible

Private Sub Command1_Click()

Dim oXL As Object ' Excel application
Dim oBook As Object ' Excel workbook
Dim oSheet As Object ' Excel Worksheet
Dim oChart As Object ' Excel Chart

Dim iRow As Integer ' Index variable for the current Row
Dim iCol As Integer ' Index variable for the current Row


Const cNumCols = 10 ' Number of points in each Series
Const cNumRows = 2 ' Number of Series
Dim aTemp(1 To cNumRows, 1 To cNumCols)


'Start Excel and create a new workbook
Set oXL = CreateObject("Excel.application")
Set oBook = oXL.Workbooks.Add
Set oSheet = oBook.Worksheets.Item(1)

' Insert Random data into Cells for the two Series:
Randomize Now()
For iRow = 1 To cNumRows
For iCol = 1 To cNumCols
aTemp(iRow, iCol) = Int(Rnd * 50) + 1
Next iCol
Next iRow
oSheet.Range("A1").Resize(cNumRows, cNumCols).Value = aTemp

'Add a chart object to the first worksheet
Set oChart = oSheet.ChartObjects.Add(50, 40, 300, 200).Chart
oChart.SetSourceData Source:=oSheet.Range("A1").Resize
(cNumRows, cNumCols)

' Make Excel Visible:
oXL.Visible = True

oXL.UserControl = True

End Sub

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Bama Cohen     Answered On: Oct 25

I think you should help yourself more before coming to the group with lists of
questions.

If you type "Set" (without the quotes) in the VBA Editor and then press F1 it
will take you to a page which explains what Set does.

The same applies to the other keywords.

You may need to look up the keyword "SetSourceData" As this is written as one
word with no spaces it is one keyword and has its own special action. It is
not the same as "Set SourceData" which has a space in it.

When you understand what the keywords mean you will be able to work out the
meaning of the code  statement. If you do it this way you will end up with a
far better understanding than if you are just told the answer.

 




Tagged: