home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Programmer'…arterly (Limited Edition) / Visual_Basic_Programmers_Journal_VB-CD_Quarterly_Limited_Edition_1995.iso / code / ch26code / listings / 26lst01.txt next >
Text File  |  1995-08-01  |  2KB  |  69 lines

  1. Option Explicit
  2. Dim Excel As Object
  3.  
  4. Sub RecordedForVB4()
  5. '********************************************************
  6. ' This code was unmodified from Excel's recorder,
  7. ' except the With Excel...End With statement. This
  8. ' statement is required because VB needs to know which
  9. ' object it should reference.
  10. '********************************************************
  11.     With Excel
  12.         .Workbooks.Add
  13.         .Range("A2").Select
  14.         .ActiveCell.FormulaR1C1 = "North"
  15.         .Range("A3").Select
  16.         .ActiveCell.FormulaR1C1 = "South"
  17.         .Range("A4").Select
  18.         .ActiveCell.FormulaR1C1 = "East"
  19.         .Range("A5").Select
  20.         .ActiveCell.FormulaR1C1 = "West"
  21.         .Range("B1").Select
  22.         .ActiveCell.FormulaR1C1 = "Spring"
  23.         .Range("C1").Select
  24.         .ActiveCell.FormulaR1C1 = "Summer"
  25.         .Range("D1").Select
  26.         .ActiveCell.FormulaR1C1 = "Fall"
  27.         .Range("E1").Select
  28.         .ActiveCell.FormulaR1C1 = "Winter"
  29.         .Range("B2").Select
  30.         .ActiveCell.FormulaR1C1 = "100"
  31.         .Range("C2").Select
  32.         .ActiveCell.FormulaR1C1 = "125"
  33.         .Range("D2").Select
  34.         .ActiveCell.FormulaR1C1 = "108"
  35.         .Range("E2").Select
  36.         .ActiveCell.FormulaR1C1 = "97"
  37.         .Range("E3").Select
  38.         .ActiveCell.FormulaR1C1 = "118"
  39.         .Range("D3").Select
  40.         .ActiveCell.FormulaR1C1 = "110"
  41.         .Range("C3").Select
  42.         .ActiveCell.FormulaR1C1 = "109"
  43.         .Range("B3").Select
  44.         .ActiveCell.FormulaR1C1 = "110"
  45.         .Range("B2:E3").Select
  46.         .Selection.AutoFill Destination:=.Range("B2:E5"), _
  47.               Type:=xlFillDefault
  48.         .Range("B2:E5").Select
  49.         .Range("A1:E5").Select
  50.         .Calculate
  51.         .Charts.Add
  52.     End With
  53. End Sub
  54.  
  55. Private Sub Command1_Click()
  56. '********************************************************
  57. ' Create the object, make Excel visible, run the macro,
  58. ' then free the object.
  59. '********************************************************
  60.     Set Excel = CreateObject("Excel.Application")
  61.     Excel.Visible = True
  62.     RecordedForVB4
  63.     Excel.ActiveWorkbook.Saved = True 'Ignore changes
  64.     MsgBox "Macro Complete!"
  65.     Excel.Quit
  66.     Set Excel = Nothing
  67.     Unload Me
  68. End Sub
  69.