Results 1 to 5 of 5

Thread: Extreme Newbie needing some help

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2006
    Posts
    3

    Extreme Newbie needing some help

    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

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Extreme Newbie needing some help

    Welcome to the Forums.

    Here is a link to some of my code for automating Excel from VB.NET.

    http://www.vbforums.com/showpost.php...38&postcount=3
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3
    Frenzied Member zaza's Avatar
    Join Date
    Apr 2001
    Location
    Borneo Rainforest Habits: Scratching
    Posts
    1,486

    Re: Extreme Newbie needing some help

    ...and in my sig you'll find a link to Excel Graphing, which looks to be your objective. Admittedly it's in VBA as well, but contains some handy ways to set it up and the syntax is more or less identical, so as long as you reference it correctly from VB you should be OK.

    zaza
    I use VB 6, VB.Net 2003 and Office 2010



    Code:
    Excel Graphing | Excel Timer | Excel Tips and Tricks | Add controls in Office | Data tables in Excel | Gaussian random number distribution (VB6/VBA,VB.Net) | Coordinates, Vectors and 3D volumes

  4. #4

    Thread Starter
    New Member
    Join Date
    Mar 2006
    Posts
    3

    Re: Extreme Newbie needing some help

    Quote Originally Posted by zaza
    ...and in my sig you'll find a link to Excel Graphing, which looks to be your objective. Admittedly it's in VBA as well, but contains some handy ways to set it up and the syntax is more or less identical, so as long as you reference it correctly from VB you should be OK.

    zaza
    Thanks guys...

    Zaza, I already have my VBA code, as I just recorded the macro.

    As you mentioned as long as a reference it correctly in VB ill be OK. Thats my problem. I am unable to properly reference it in VB.

    I believe I have all the proper imports, what Im uncertain on is how to DIM excel.

    I know that I need to add "app." in front of things that reference an active chart ect. I also know that I need to add an "excel.xlaxistype." in front of things like .xlXYScatterSmoothNoMarkers and xlaxisgroup.xlPrimary.

    The problem is that I dont know if thats all I need to do. When I add excel. to any line I get a blue squiggly under the word excel. That is why I dimensioned excel as a new app, but im uncertain if that is the proper dimension.

    I know this is probably trivial, but Ive never done this before, and I only need to do it once.

  5. #5
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Extreme Newbie needing some help

    Did you check my example code?

    Did you add the reference and the declarations of the application object like in my code? Post an update of your code in vb.net.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width