?????? ??????This article applies to a different operating system than the one you are using. Article content that may not be relevant to you is disabled.
'Display a message box that displays the application name.
Public Sub DoKbTest()
MsgBox "Hello from " & Application.Name
End Sub
'Display a message box with the string passed from the
'Automation client.
Public Sub DoKbTestWithParameter( sMsg As String )
MsgBox sMsg
End Sub
Visual Basic ?????? ?? ??? ????, Word ???????? ?? ??????, ?? Word ?? ???? ???????
Select Case ComboBox1.SelectedItem
Case "Access"
Dim oAccess As Access.ApplicationClass
'Start Access and open the database.
oAccess = CreateObject("Access.Application")
oAccess.Visible = True
oAccess.OpenCurrentDatabase("c:\db1.mdb", False)
'Run the macros.
oAccess.Run ("DoKbTest")
oAccess.Run("DoKbTestWithParameter", "Hello from VB .NET Client")
'Clean-up: Quit Access without saving changes to the database.
oAccess.DoCmd().Quit (Access.AcQuitOption.acQuitSaveNone)
System.Runtime.InteropServices.Marshal.ReleaseComObject (oAccess)
oAccess = Nothing
Case "Excel"
Dim oExcel As Excel.ApplicationClass
Dim oBook As Excel.WorkbookClass
Dim oBooks As Excel.Workbooks
'Start Excel and open the workbook.
oExcel = CreateObject("Excel.Application")
oExcel.Visible = True
oBooks = oExcel.Workbooks
oBook = oBooks.Open("c:\book1.xls")
'Run the macros.
oExcel.Run ("DoKbTest")
oExcel.Run("DoKbTestWithParameter", "Hello from VB .NET Client")
'Clean-up: Close the workbook and quit Excel.
oBook.Close (False)
System.Runtime.InteropServices.Marshal.ReleaseComObject (oBook)
oBook = Nothing
System.Runtime.InteropServices.Marshal.ReleaseComObject (oBooks)
oBooks = Nothing
oExcel.Quit()
System.Runtime.InteropServices.Marshal.ReleaseComObject (oExcel)
oExcel = Nothing
Case "PowerPoint"
Dim oPP As PowerPoint.ApplicationClass
Dim oPresSet As PowerPoint.Presentations
Dim oPres As PowerPoint.PresentationClass
'Start PowerPoint and open the presentation.
oPP = CreateObject("PowerPoint.Application")
oPP.Visible = True
oPresSet = oPP.Presentations
oPres = oPresSet.Open("c:\pres1.ppt", , , True)
'Run the macros.
oPP.Run ("'pres1.ppt'!DoKbTest")
oPP.Run("'pres1.ppt'!DoKbTestWithParameter", "Hello from VB .NET Client")
'Clean-up: Close the presentation and quit PowerPoint.
oPres.Close()
System.Runtime.InteropServices.Marshal.ReleaseComObject (oPres)
oPres = Nothing
System.Runtime.InteropServices.Marshal.ReleaseComObject (oPresSet)
oPresSet = Nothing
oPP.Quit()
System.Runtime.InteropServices.Marshal.ReleaseComObject (oPP)
oPP = Nothing
Case "Word"
Dim oWord As Word.ApplicationClass
'Start Word and open the document.
oWord = CreateObject("Word.Application")
oWord.Visible = True
oWord.Documents.Open ("C:\Doc1.doc")
'Run the macros.
oWord.Run ("DoKbTest")
oWord.Run("DoKbTestWithParameter", "Hello from VB .NET Client")
'Quit Word.
oWord.Quit()
System.Runtime.InteropServices.Marshal.ReleaseComObject (oWord)
oWord = Nothing
End Select
GC.Collect()