Results 1 to 1 of 1

Thread: [FAQ's: OD] How do I make my first VSTO 2003 application?

  1. #1

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

    [FAQ's: OD] How do I make my first VSTO 2003 application?

    Meow.NET!


    VSTO 2003 And Excel 2003

    VB Code:
    1. Option Explicit On
    2. Option Strict Off
    3.  
    4. Imports System.Windows.Forms
    5. Imports Office = Microsoft.Office.Core
    6. Imports Excel = Microsoft.Office.Interop.Excel
    7. Imports MSForms = Microsoft.Vbe.Interop.Forms
    8.  
    9. ' Office integration attribute. Identifies the startup class for the workbook. Do not modify.
    10. <Assembly: System.ComponentModel.DescriptionAttribute("OfficeStartupClass, Version=1.0, Class=Excel_VSTO_1.OfficeCodeBehind")>
    11.  
    12. Public Class OfficeCodeBehind
    13.  
    14.     Friend WithEvents ThisWorkbook As Excel.Workbook
    15.     Friend WithEvents ThisApplication As Excel.Application
    16.  
    17. #Region "Generated initialization code"
    18.  
    19.     ' Default constructor.
    20.     Public Sub New()
    21.         Application.EnableVisualStyles()
    22.         Application.DoEvents()
    23.     End Sub
    24.  
    25.     ' Required procedure. Do not modify.
    26.     Public Sub _Startup(ByVal application As Object, ByVal workbook As Object)
    27.         ThisApplication = CType(application, Excel.Application)
    28.         ThisWorkbook = CType(workbook, Excel.Workbook)
    29.     End Sub
    30.  
    31.     ' Required procedure. Do not modify.
    32.     Public Sub _Shutdown()
    33.         ThisApplication = Nothing
    34.         ThisWorkbook = Nothing
    35.     End Sub
    36.  
    37.     ' Returns the control with the specified name on ThisWorkbook's active worksheet.
    38.     Overloads Function FindControl(ByVal name As String) As Object
    39.         Return FindControl(name, CType(ThisWorkbook.ActiveSheet, Excel.Worksheet))
    40.     End Function
    41.  
    42.     ' Returns the control with the specified name on the specified worksheet.
    43.     Overloads Function FindControl(ByVal name As String, ByVal sheet As Excel.Worksheet) As Object
    44.         Dim theObject As Excel.OLEObject
    45.         Try
    46.             theObject = CType(sheet.OLEObjects(name), Excel.OLEObject)
    47.             Return theObject.Object
    48.         Catch Ex As Exception
    49.             ' Returns Nothing if the control is not found.
    50.         End Try
    51.         Return Nothing
    52.     End Function
    53. #End Region
    54.  
    55.     ' Called when the workbook is opened.
    56.     Private Sub ThisWorkbook_Open() Handles ThisWorkbook.Open
    57.         Dim usrForm1 As MSForms.UserForm
    58.         Dim btn As MSForms.CommandButton
    59.  
    60.         usrForm1.Caption = "VSTO Set This Caption"
    61.  
    62.     End Sub
    63.  
    64.     ' Called before the workbook is closed. Note that this method
    65.     ' might be called multiple times and the value assigned to Cancel
    66.     ' might be ignored if other code or the user intervenes.
    67.     ' Cancel is False when the event occurs. If the event procedure
    68.     ' sets this to True, the document does not close when the procedure is finished.
    69.     Private Sub ThisWorkbook_BeforeClose(ByRef Cancel As Boolean) Handles ThisWorkbook.BeforeClose
    70.         Cancel = False
    71.     End Sub
    72.  
    73. End Class
    Last edited by RobDog888; Aug 23rd, 2006 at 04:34 PM.
    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