title: OLE: Inaccessible due to its protection level.
body: <p>I am trying to plot a chart in excel sheet using VB. </p>
  
  <p>So now I am following the instructions given  <a href="http://support.microsoft.com/kb/142387" rel="nofollow">here</a>      </p>
  
  <p>1- I started a new VB project in VS2010, called Excelgraph.</p>
  
  <p>2- By default I got Form1.vb[Design].</p>
  
  <p>3- On this Form I created a button by dragging it from the toolbox. </p>
  
  <p>4-I doubled clicked it and new Form1.vb opens. </p>
  
  <p>5- I removed everything that was automatically generated in this file i,e Form1.vb file and pasted the following code:  </p>
  
  <p><strong>Updated Code</strong></p>
  
  <p>This is another code and is a latest one, compatible with Visual Basic 6.0.  </p>
  
  <pre><code> Public Class Form1
  
  
  
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As 
    System.EventArgs) Handles Button1.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
  
  
      ReDim aTemp(0 To cNumRows, 0 To cNumCols)
  
      'Start Excel and create a new workbook
      oXL = CreateObject("Excel.application")
      oBook = oXL.Workbooks.Add
      oSheet = oBook.Worksheets.Item(1)
  
      ' Insert Random data into Cells for the two Series:
      Randomize(Now().ToOADate())
      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
      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
  
  
  
  End Class
  </code></pre>
  
  <p><strong>Update</strong></p>
  
  <p>I updated the code as shown above.  </p>
  
  <p><strong>Error</strong> </p>
  
  <pre><code>    'aTemp' is not declared. It may be inaccessible due to its protection level.    
       c:\users\ybf4 \documents\visual studio 2010\Projects\Excelgraph2
       \Excelgraph2\Form1.vb
  </code></pre>
  
  <p>There were two more errors which I managed to remove. How do I remove this error?</p>
  
  <p>I am compiling the above code on visual studio 2010 and Office is Office 2007. </p>