Hello guys

3rd year EE student here, needing some help.

Im taking a visual basic class, and to make a long story short. I have a program in which I need it to do some functions in Excel.

What I did was open excel, and record a Macro. This gave me my VBA code, I now need to get that code working in VB. Can anyone help me out.

Here is the code:

VB Code:
  1. app.Columns("C:C").Select()
  2. Selection.NumberFormat = "0.00"
  3. Range("K6").Select()
  4. Charts.Add()
  5. ActiveChart.ChartType = .xlXYScatterSmoothNoMarkers
  6. ActiveChart.SetSourceData(Source:=app.Sheets("Sheet1").Range("B:B,C:C"), PlotBy _
  7. :=.xlrowcol.xlColumns)
  8. ActiveChart.Location(Where:=Xlchartlocation.xllocationasnewsheet)
  9. With ActiveChart
  10. .HasTitle = False
  11. .HasAxes(.xlCategory, excel.xlaxisgroup.xlPrimary).HasTitle = False
  12. .Axes(.xlValue, xlPrimary).HasTitle = False
  13. End With
  14. ActiveChart.Axes(xlValue).Select()
  15. With ActiveChart.Axes(xlValue)
  16. .MinimumScale = -5
  17. .MaximumScale = 5
  18. .MinorUnitIsAuto = True
  19. .MajorUnitIsAuto = True
  20. .Crosses = excel.xlAutomatic
  21. .ReversePlotOrder = False
  22. .ScaleType = excel.xlLinear
  23. .DisplayUnit = excel.xlNone
  24. End With
  25. ActiveChart.SeriesCollection(1).Select()
  26. ActiveChart.Axes(xlCategory).Select()
  27. With ActiveChart.Axes(excel.xlCategory)
  28. .MinimumScale = 0
  29. .MaximumScale = 1024
  30. .MinorUnitIsAuto = True
  31. .MajorUnitIsAuto = True
  32. .Crosses = excel.xlAutomatic
  33. .ReversePlotOrder = False
  34. .ScaleType = xlLinear
  35. .DisplayUnit = xlNone
  36. End With
  37. ActiveChart.SeriesCollection(1).Select()
  38. ActiveChart.SeriesCollection(1).Points(147).Select()
  39. ActiveChart.SeriesCollection(1).Points(102).Select()
  40. ActiveChart.SeriesCollection(1).Points(14).Select()
  41. ActiveChart.SeriesCollection(1).Points(38).Select()
  42. ActiveChart.SeriesCollection(1).Points(59).Select()
  43. ActiveChart.SeriesCollection(1).Points(39).Select()
  44. ActiveChart.SeriesCollection(1).Points(25).Select()
  45. ActiveChart.SeriesCollection(1).Points(50).Select()
  46. ActiveChart.SeriesCollection(1).Points(103).Select()
  47. ActiveChart.SeriesCollection(1).Points(83).Select()
  48. ActiveChart.SeriesCollection(1).Points(62).Select()
  49. ActiveChart.PlotArea.Select()
  50. ActiveChart.SeriesCollection(1).Select()
  51. ActiveChart.SeriesCollection(1).Points(71).Select()
  52. ActiveChart.PlotArea.Select()
  53. ActiveChart.SeriesCollection(1).Select()
  54. With app.Selection.Border
  55. .ColorIndex = 57
  56. .Weight = xlThick
  57. .LineStyle = xlContinuous
  58. End With
  59. With app.Selection
  60. .MarkerBackgroundColorIndex = xlNone
  61. .MarkerForegroundColorIndex = xlNone
  62. .MarkerStyle = xlNone
  63. .Smooth = True
  64. .MarkerSize = 3
  65. .Shadow = False
  66. End With
  67. ActiveChart.PlotArea.Select()
  68. ActiveChart.Deselect()
  69. ActiveChart.ChartArea.Select()
  70. With ActiveChart
  71. .HasAxis(xlCategory, xlPrimary) = False
  72. .HasAxis(xlValue, xlPrimary) = False
  73. End With
  74. ActiveChart.Axes(excel.xlCategory, excel.xlPrimary).CategoryType = xlAutomatic
  75. With app.ActiveChart.Axes(xlCategory)
  76. .HasMajorGridlines = False
  77. .HasMinorGridlines = False
  78. End With
  79. With ActiveChart.Axes(xlValue)
  80. .HasMajorGridlines = False
  81. .HasMinorGridlines = False
  82. End With
  83. ActiveChart.HasLegend = False
  84. ActiveChart.PlotArea.Select()
  85. With Selection.Border
  86. .ColorIndex = 16
  87. .Weight = xlThin
  88. .LineStyle = xlContinuous
  89. End With
  90. Selection.Fill.UserPicture(PictureFile:= _
  91. "C:\Documents and Settings\sbishop\Desktop\SCOPEcrop.bmp")
  92. Selection.Fill.Visible = True

Here is what I do know. I know that I need to add alot of App. and Excel.

I also am currently dimensioning excel as "Dim excel As New Application"

Im not sure if thats the proper way to dimension excel.

Also, here are my imports statements:

Imports System.Drawing
Imports System
Imports System.Reflection
Imports System.Runtime.InteropServices
Imports Microsoft.office.interop.Excel

this is not a traditional VB class, our focus isnt solely on VB, but rather just using VB as a medium to integrate a USB microcontroller with Windows Applications.

any help would be appreciated