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

?????? ????????? ?????? ?????????
???? ???????: 303871 - ??? ???????? ???? ????? ????? ??? ???????.
????? ???? | ?? ????

?? ??? ??????

??????

???? ??? ??????? ???? ????? ??? ????? ???? Microsoft Excel ?? Microsoft Visual Basic .NET ?????? ???? ????? ??? ????? ???? ????? ?? CommandBar.

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

  1. ??? ????? Microsoft Visual Basic .NET.
  2. ?? ??????? ???? ???? ??? ???? ?? ???? ??? ???????. ??? ????? Windows ?? ????? ?????? Visual Basic. ??? ????? Form1 ???? ???????.
  3. ????? ????? ??? ????? ?????? Microsoft Excel "?" ????? ?????? Microsoft Office "?" Microsoft Visual Basic ?????? ??????? ?????????. ?????? ????? ???? ??????? ???????:
    1. ?? ??????? ??????? ???? ??? ????? ????.
    2. ???? ??? ????? ??????? COM ???? ??? ????? ?????? Microsoft Excel ?? ???? ??? ?????.

      ?????? ????? Microsoft Office 2003 ????????? ??????? ??????? ???????? ???????? (PIAs). ?? ????? Microsoft Office XP PIAs ???? ?? ??? ?????. ?????? ??? ??????? ?????? ??? Office XP PIAs ? ???? ??? ??? ??????? ?????? ?????? ?? "????? ??????? ?? Microsoft:
      328912INFO: Microsoft Office XP PIAs ???????? ???????
    3. ??? Microsoft Visual Basic ?????? ??????? ????????? ?? ???? ??? ?????.
    4. ???? ??? ????? ?? ???? ?????? ????? ????? ????? ?????????.
  4. ?? ??????? ???? ???? ??? ???? ????? ???? ???? ??????? ?? ????? ?? ??? Form1.
  5. ???? ????? ??????? ??? Button1. ??? ??? ???? ????????? ???????? ?? ????? onClick ?? Button1. ?? ?????? ????? ?????? ??? "????? ???" Form1:
       Imports Office = Microsoft.Office.Core
    					
  6. ?? ?????? "??????? ??????" ? ?? ?????? ????????? ???????? ???????:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
          System.EventArgs) Handles Button1.Click
       Dim oExcel As Excel.Application
       Dim oBook As Excel.Workbook
       Dim oModule As VBIDE.VBComponent
       Dim oCommandBar As Office.CommandBar
       Dim oCommandBarButton As Office.CommandBarControl
       Dim sCode As String
    
       ' Create an instance of Excel, and show it to the user.
       oExcel = New Excel.Application()
    
       ' Add a workbook.
       oBook = oExcel.Workbooks.Add
    
       ' Create a new VBA code module.
       oModule = oBook.VBProject.VBComponents.Add(VBIDE.vbext_ComponentType.vbext_ct_StdModule)
    
       sCode = "sub VBAMacro()" & vbCr & _
          "   msgbox ""VBA Macro called"" " & vbCr & _
          "end sub"
    
       ' Add the VBA macro to the new code module.
       oModule.CodeModule.AddFromString(sCode)
    
       Try
          ' Create a new toolbar, and show it to the user.
          oCommandBar = oExcel.CommandBars.Add("VBAMacroCommandBar")
          oCommandBar.Visible = True
    
          ' Create a new button on the toolbar.
          oCommandBarButton = oCommandBar.Controls.Add(Office.MsoControlType.msoControlButton)
          ' Assign a macro to the button.
          oCommandBarButton.OnAction = "VBAMacro"
          ' Set the caption of the button.
          oCommandBarButton.Caption = "Call VBAMacro"
          ' Set the icon on the button to a picture.
          oCommandBarButton.FaceId = 2151
       Catch exc As Exception
             MessageBox.Show("VBAMacroCommandBar already exists.", "Error")
       End Try
    
       oExcel.Visible = True
       ' Set the UserControl property so that Excel does not shut down.
       oExcel.UserControl = True
    
       ' Release the variables.
       oCommandBarButton = Nothing
       oCommandBar = Nothing
       oModule = Nothing
       oBook = Nothing
       oExcel = Nothing
    
       ' Force garbage collection.
       GC.Collect()
    
    End Sub
    					
  7. ?? ?????? ????????? ???????? ??????? ??? ???? Form1.vb:
    Imports Office = Microsoft.Office.Core
    Imports Microsoft.Office.Interop
    Imports VBIDE = Microsoft.Vbe.Interop
    					
  8. ???? F5 ?????? ???????? ??????? ??.
  9. ???? ??? Button1 ??? ????? Excel ????? Visual Basic for Applications (VBA) ??? ?? ?? ?????? ???? ???? CommandBar ????. ???? ??? ???? ??? CommandBar ?????? VBA ?? ???????.

??????? ?????? ?? Office XP

??????? Microsoft Office XP ? Microsoft Office 2003 ??? ???? ???? ???? ??????? ??????? ??? ???? ???? VBA. ??? ??? ??? ??????? ????? (?????????) ? ?? ????? ??? ??? ????? ????? ???????? ????????. ?????? ??? ??????? ?????? ??? ??? ??????? ??? ????? ????? ????? ???? ??? ??? ??????? ?????? ?????? ?? "????? ??????? ?? Microsoft:
282830PRB: ?? ??? ?????? ??????? ??? ????? VBA XP Office

?????

?????? ??? ??????? ??????? ???? ??? ??? ??????? ?????? ?????? ?? "????? ??????? ?? Microsoft:
194611????? ? ?????? ??? ????? Excel ??????? ?? VB

???????

???? ???????: 303871 - ????? ??? ??????: 26/????? ??????/1425 - ??????: 7.2
????? ???
  • Microsoft Visual Basic .NET 2003 Standard Edition
  • Microsoft Visual Basic .NET 2002 Standard Edition
  • Microsoft Office Excel 2003
  • Microsoft Excel 2002 Standard Edition
????? ??????: 
kbmt kbpia kbautomation kbhowtomaster KB303871 KbMtar
????? ????
???: ??? ????? ??? ?????? ???????? ?????? ????? ???? ????? ?????????? ????? ?? ????????? ?????? ????. ???? ???? ?????????? ???? ?? ???????? ???????? ?????? ????????? ????? ????????? ???????? ????? ???????? ?????? ?? ?????? ??? ?? ???????? ???????? ?? ????? ??????? ?????? ??? ??????? ?????? ??. ?????? ?? ???? ??? ??????? ???????? ????? ?? ???? ????? ?????? ??? ????? ??? ????? ??????? ?? ????? ?? ?????? ??? ??? ??????? ??????? ?? ????? ????? ????? ????? ?????. ?? ????? ???? ?????????? ??????? ??? ????? ?? ??????? ?? ????? ?????? ?? ??? ????? ?? ????? ??????? ?? ???????? ?? ??? ???????. ???? ???? ?????????? ???????? ??? ????? ?????? ??????? ??????
???? ??? ????? ??????? ?????? ??????????303871

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

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com