???? ID: 306682 - ????? ???????: 04 ?????? 2010 - ??????: 2.0

Visual Basic .NET ?? ??????? ?? ????? ?? Office ?????? ?? ????? ?? ??? ???? ????

?????? ??????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.
?? Microsoft Visual C# .NET ??????? ?? ??? ?? ???? ??, ?????306683  (http://support.microsoft.com/kb/306683/ ) .
?? Microsoft Visual C++ ??????? ?? ??? ?? ???? ??, ?????306686  (http://support.microsoft.com/kb/306686/ ) .

?? ????? ??

??? ?? ??????? ???? | ??? ?? ??????? ????

??????

?? ??? ?? ??? ???? ????? ?? ?? ???? Office ?? ??? ???? ?? ??? ??? Visual Basic .NET ??????? ??????? ?? ????????

???? ???????? ?? ????? ?? ????????? (VBA) ?????? ?? ??? ??? Visual Basic ??? ?? ??? ???????? ????? ?? ?????? ????? ??? ?? ????????? ???? ?? ??? ?? Microsoft Office ??????? ?? ????? ?? ?????

???? ???????

????? ????? ??????? ??????? manipulates ??? Office ??????? ????? (?????, Excel, PowerPoint ?? Word) ?? ???? ??????? ??? ???? ??? ?? ?????? ??? ??????? ??????? ????? ?? ??????? ???? ??, ?? ??? ??? ???? ???????? ?? ????? ?? ?? ?? ??????? ?? ?? ??? ????? ???? ??????, DoKbTest, ??? ???????? ???? ?? ?? ????? ??????, DoKbTestWithParameter, ?? ?? ?????? ?? ??? ??? ???????? ???? ??????????.

?????? ??? office ???????? ?????

  1. ???? Word ???????? C:\Doc1.doc ??? ?????? ??? ???? ?? ???, ????? ????? ?? ???? ????::
    1. Word ??? ??? ??? ????????? ??????
    2. Visual Basic Editor ????? ?? ??? ALT + F11 ??????
    3. ????? ???????????? ???????? ??,???????.
    4. ?? ??????? ??? ????? ?????? ??? ???????:
      '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
    5. Visual Basic ?????? ?? ??? ????, Word ???????? ?? ??????, ?? Word ?? ???? ???????
  2. ?? Word ???????? ????? ?? ??? ????? ???? ?? ??? ???? ????? ?? ????? ???? C:\Book1.xls ?? ??? Excel ????????????? ??????
  3. PowerPoint ????????? C:\Pres1.ppt ?? ???? ?? ?? Word ?? ????? ?? ??? ????? ???? ?? ??? ????? ?? ????? ???? ??? ????? ?????????
  4. C:\Db1.mdb ???? ?? Access ??????? ?????? ??? ???? ?? ???, ????? ????? ?? ???? ????::
    1. ????? ???????????? ???????? ??,???????.
    2. ?? ??????? ??? ?????? ??? ?? ????????
    3. ??????? ??????, ?? ????? ?? ???? ???????

Visual Basic .NET ??????? ??????? ?????

  1. Microsoft Visual Studio .NET ???? ????.. ????? ???????????? ??,????? ????-????? ????, ?? ???? ????????????. ??? ????Windows ??????????? Visual Basic ????????? ??????? Form1 ???????? ??? ?? ???? ??..
  2. ?????, Excel, PowerPoint, ?? Word ???????? ????????? ?? ??? ??? ?????? ??????? ??? ???? ?? ???, ????? ????? ?? ???? ????::
    1. ????? ????????????????? ??,?????? ??????.
    2. ????? ????COM??? ??, ??????Microsoft Word 10.0 ???????? ????????? ?? Microsoft Word 11.0 ???????? ??????????? ????-????? ????, ?? ???? ?????? ????.

      ???:??? ?? Microsoft Office XP ?? ????? ?? ??? ??? ?? ???? ??? ??? ?? ???? ??, ?? Microsoft ??????? ???? ?? ?? ??????? ???? ?? ???? ??? Microsoft Office XP ???????? Interop Assemblies (PIAs) ??????? ?????Office XP PIA ?? ???? ??? ???? ??????? ?? ???, ????? ???? ?????? ?? ????? ?? ???? ?? Microsoft ???????? ??? ?????::
      328912  (http://support.microsoft.com/kb/328912/ ) Microsoft Office XP ???????? ?????? assemblies (PIAs) ??????? ???? ?? ??? ?????? ???
    3. ?????, Excel, ?? PowerPoint ???????? ????????? ?? ??? ????? ??? ?? ????????
    4. ????? ????,OK??????????? ??????????? ????? ???? ??? ?? ??????? ???? ?? ??? ??? ??? ???? ?? ????????? ?? ?? ???? ?????? ????? ???? ?? ??? wrappers ????? ???? ?? ??? ????? ????, ?? ????? ???????.

      ???:??? ???? ?? ?????? ????? ?? ?? Access ?????? 10.0 ????????? ???????? ??, "?????? ??????" ??? ??????
  3. ????? ????????????? ??,????? ?????. Form1 ?? ??? ??? ?????? ????? ?? ?? ??? ???????
  4. ???-????? ????Button1??? ?? ??? ???? ??????? ????? ???? ?? ??? ????? ?? ????? ???????
  5. Button1_Click ????????? ??? ?????????? ??? ?? ???????:
    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() 
  6. ????? ????????????? ??,Designer?? ???-????? ????Form1??????? ??? ????? ?? ??? ???? ??????? ????? ?????
  7. Form1_Load ????????? ??? ?????????? ??? ?? ???????:
            ComboBox1.DropDownStyle = ComboBoxStyle.DropDownList
            Dim a As String() = {"Access", "Excel", "PowerPoint", "Word"}
            ComboBox1.Items.AddRange(a)
            ComboBox1.SelectedIndex = 0
    					
  8. ????? ??? Form1.vb ?? ???? ??? ??? ??????:
    Imports Access = Microsoft.Office.Interop.Access
    Imports Excel = Microsoft.Office.Interop.Excel
    Imports Word = Microsoft.Office.Interop.Word
    Imports PowerPoint = Microsoft.Office.Interop.PowerPoint
    					

??????? ??????? ?? ??????? ???? ?? ?????

  1. ????????? ?? ????? ?? ??? F5 ??????
  2. ?? ???? Office ????????? ?? ??? ????ComboBox1?? ????-????? ????, ?? ???? ???Button1. ???? ?????? ????? Office ????????? ??????? ???? ??? ?? ?? DoKBTest ?? DoKBTestWithParameter ?????? ?? ???????? ???

?????? ??????

?? ?? ?????? ??? ??? .NET ?? Visual Basic ????????? ????? 10.0 ???????? ????????? ??, ?? ????? ?? ?? ??? .NET ??????? ???? ?? ??? ????????? ?? ??????? ???? ?????? ????? ??? ???? ???????? ?? ???? ????? 10.0 ???????? ????????? ?????? ?? ?????? ?? ?? ???? ?? ??? ???? ???? ?? ???? ??? ???? ??????? ?? ??? Microsoft ???????? ??? ???? ????? ?? ??? ????? ???? ?????? ?? ????? ????:
317157  (http://support.microsoft.com/kb/317157/ ) PRB: ?? ?? Visual Studio .NET ?? ????? 10.0 ?????? ????????? ?????? ??????

??????

???? ??????? ?? ???, Microsoft ?????? ??? ??? ???? ????? ?? ??? ????? ???? ?????? ????? ????::
303871  (http://support.microsoft.com/kb/303871/ ) Visual Basic .NET ?? ??????? ?? ????? ?? Excel ?? ???? ?????? ?? ????? ?? ??? ???? ????
177760  (http://support.microsoft.com/kb/177760/ ) ACC97: ???? Office ??????????? ??? ?????? ????? ?? ??? ????
???? ??????? ?? Office ?? ???? ??? ???????? ?? ??? ??????? ?? ???, ????? Microsoft ??? ???? ?? ????:
Visual Studio ?? ??? Microsoft Office ??????????
http://msdn2.microsoft.com/en-us/library/aa188489(office.10).aspx (http://msdn2.microsoft.com/en-us/library/aa188489(office.10).aspx)

FAQs ?? Office ????????? ?? ??? ?????????
HTTP://msdn2.Microsoft.com/en-us/Office/default.aspx (http://msdn2.microsoft.com/en-us/office/default.aspx)

???? ???? ???? ??:
  • Microsoft Visual Basic .NET 2003 Standard Edition
  • Microsoft Visual Basic .NET 2002 Standard Edition
  • Microsoft Access 2002 Standard Edition
  • Microsoft Excel 2002 Standard Edition
  • Microsoft PowerPoint 2002 Standard Edition
  • Microsoft Word 2002
  • Microsoft Office Access 2003
  • Microsoft Office PowerPoint 2003
??????: 
kbautomation kbhowto kbmt KB306682 KbMthi
???? ?????? ???????????? ?????? ????????
??????????: ?? ???? ?? ???? ??????? ?? ????? ?? Microsoft ????-?????? ?????????? ?????? ?????? ???? ??? ??. Microsoft ???? ??? ????-???????? ?? ????-???????? ????? ?????? ?? ???? ???????? ???? ?? ???? ????? ????? ??? ?? ??? ?????? ?? ???? ???? ???? ??? ????? ??. ???????, ????-???????? ???? ????? ???? ???? ???? ???. ?????, ????????, ?????-???? ?? ??????? ?? ???????? ?? ???? ???, ???? ?? ??? ?????? ???? ???? ??? ????? ??? ?? ???? ??. Microsoft ??????? ??? ???? ?? ?????? ?? ??????????, ????????? ?? ??? ?????? ?? ???? ????? ?? ???? ???????? ?? ??? ???? ????? ?? ??? ????????? ???? ??. Microsoft ????-?????? ?????????? ?? ????? ?????? ?? ?? ??? ??.
?????????? ?? ??????? ????????? ??????? ??:306682  (http://support.microsoft.com/kb/306682/en-us/ )