title: Resetting variable at every workbook open
body: <p>I've got a macro that draws a chart from given data. There's possibility that in the same workbook there will be made several more charts. I'd like to set chart to a certain place and make it certain size by using the same macro. The thing is, only thing I came up to to make this happen had this line:</p>
  
  <pre><code>ActiveSheet.Shapes("Chart 1").&lt;whatever option goes here&gt;
  </code></pre>
  
  <p>(or another number if it's next chart)</p>
  
  <p>I'd like make it like this:</p>
  
  <pre><code>ActiveSheet.Shapes("Chart " &amp; x).&lt;option&gt;
  </code></pre>
  
  <p>The only thing I can't figure out is how to make that <code>x</code> reset at every time I open the workbook to make it work properly. I kinda know it's related to <code>workbook_open()</code> and probably <code>Public x As Integer</code> but I have no idea how to put it together. I've tried some combinations of it but didn't work.</p>
  
  <p>My whole code:</p>
  
  <pre><code>Sub import()
  
  
  Fname = Application.GetOpenFilename
  
  If Fname = False Then Exit Sub
  
  Sheets("Arkusz2").Select
  Columns("A:F").Select
  Selection.ClearContents
  Selection.ColumnWidth = 8.43
  
  Dim wks As Worksheet
  
  For Each wks In Worksheets
      If wks.ChartObjects.Count &gt; 0 Then
          wks.ChartObjects.Delete
      End If
  Next wks
  
  
  
  
  
  Workbooks.OpenText Filename:= _
      Fname, Origin:=437 _
      , StartRow:=1, DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, _
      ConsecutiveDelimiter:=False, Tab:=True, Semicolon:=False, Comma:=True _
      , Space:=False, Other:=False, FieldInfo:=Array(Array(1, 1), Array(2, 1)), _
      TrailingMinusNumbers:=True, DecimalSeparator:=".", ThousandsSeparator:=","
  
  
  Range("B1").Value = DateValue(Range("B1").Value)
  
  Range("B4, B5, B6, B8").Activate
      Selection.Replace What:=".", Replacement:=",", LookAt:=xlPart, _
      SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
      ReplaceFormat:=False
  
  Range("B21:C100").Select
      Selection.NumberFormat = "0.000E+00"
  
  Range("B2").Select
  Selection.NumberFormat = "[$-x-systime]h:mm:ss AM/PM"
  
  
  
  
  Columns("A:A").EntireColumn.AutoFit
  Columns("B:B").EntireColumn.AutoFit
  Columns("C:C").EntireColumn.AutoFit
  Columns("D:D").EntireColumn.AutoFit
  Columns("E:E").EntireColumn.AutoFit
  
  
  ark = ActiveWorkbook.Name
  
  Columns("A:E").Select
  Selection.Copy
  Windows("import danych.xlsm").Activate
  Sheets("Arkusz2").Select
  ActiveSheet.Paste
  Range("A1").Select
  
  Windows(ark).Activate
  Application.CutCopyMode = False
  ActiveWindow.Close savechanges = True
  Windows("import danych.xlsm").Activate
  Application.CutCopyMode = False
  
  Run "graph"
  
  
  
  
  End Sub
  
  Sub graph()
  
  
  
  target = Range("B11").Value
  dat = Range("B1").Value
  
  Dim tim As Date
  tim = Range("b2").Value
  typ = Range("B7").Value
  
  Cells.Find(What:="Ref signaal [A]", After:=ActiveCell, LookIn:=xlFormulas _
      , LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
      MatchCase:=False, SearchFormat:=False).Activate
  
  
  ActiveCell.Offset(1, 0).Select
  
  c = ActiveCell.Row - 1
  
  d = ActiveCell.Value
  
  Do Until d = ""
  
  c = c + 1
  
  ActiveCell.Offset(1, 0).Select
  d = ActiveCell.Value
  
  Loop
  
  Cells.Find(What:="Ref signaal [A]", After:=ActiveCell, LookIn:=xlFormulas _
      , LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
      MatchCase:=False, SearchFormat:=False).Activate
  
  ActiveCell.Offset(0, 2).Select
  
  r1 = ActiveCell.Address
  
  ActiveCell.Offset(0, 1).Select
  
  ActiveCell.FormulaR1C1 = "Target"
  
  ActiveCell.Offset(1, 0).Select
  r2 = ActiveCell.Address
  
  ActiveCell.FormulaR1C1 = target
  Application.CutCopyMode = False
  Selection.AutoFill Destination:=Range(r2 &amp; ":F" &amp; c)
  
  
  Range(r1 &amp; ":F" &amp; c).Select
  ActiveSheet.Shapes.AddChart2(227, xlLine).Select
  ActiveChart.SetSourceData Source:=Range("Arkusz2!$E$21:$F$" &amp; c)
  
  ActiveChart.FullSeriesCollection(2).Select
  With Selection.Format.Line
      .ForeColor.RGB = RGB(255, 0, 0)
  End With
  
  ActiveChart.FullSeriesCollection(1).Select
  ActiveChart.FullSeriesCollection(1).ChartType = xlLineMarkers
  
  ActiveChart.ChartTitle.Select
  ActiveChart.ChartTitle.Text = dat &amp; " " &amp; tim &amp; " " &amp; typ
  
  Range("A1").Select
  End Sub
  </code></pre>