VBA ?? Office ?????? ?? ????? ?? ?????? Office COM ??-?? ?? ????? ???? ????

???? ?????? ???? ??????
???? ID: 306130 - ?? ???????? ?? ?????? ??? ?? ?? ???? ???? ???? ??.
??? ?? ??????? ???? | ??? ?? ??????? ????

?? ????? ??

??????

?? ???? ????? ???? ?? ?? ???? UserForm ?? ?? Microsoft Excel ?? Microsoft Word ??????? ???? ?? ???? welcomes ????????? ???? ?? ??? ???? ????? ??? ???????? ???? (COM) ??-???? ???? ??? ??? ?????? ????????-???? ????????? (DLL) ?? ???? ?? ????? ?? ???? ???? ?? Office ??? ?? ??????? ??? centralize ???? ?? ??? ?? ?????? ????????? (?????? ?? ???, ?? ?? ????? ???? Microsoft Outlook ?????? Excel, Word ?? Microsoft Access ??)? Microsoft Office ??? ??? COM DLL ?? ?????? ???? ?? ??? easiest ????? ?? ?? ??-?????????, ?? designer ?? ?? ?????? ???? ?? ?? ??? ??? ???? ?? ??? ??IDTExtensibility2????????? ????

??????????

?? ???? ????? ?? ?? ?? ????? ???? ?? ?????? ???:

  • ???? Office XP ????????? ??? ????????? (VBA) ???????????? ?? ??? Visual Basic ??? ??? ???
  • VBA ??? UserForms ?? ??? ????? ?? ??? ???
  • Office XP ????? ???????? ???????? ???? ???

??? ??-?? ????????? ?????

?? ???? ??? Microsoft Office 2000 ?????? ?? Microsoft Office XP ?????? ????? ??????? ???? ?? Microsoft Office 2000 ?? Microsoft Office XP ????????? ??? ?? ??-?? ????????? ?? ??? ???? ???? ?? ?????? Microsoft Word 2002 ?? ????? ???? ???
  1. Microsoft Word 2002 ?? ??????? ?????
  2. ??????????? ??,???????? ????-????? ????, ?? ???? ???Visual Basic ??????.
  3. ??? Visual Basic ?????? (VBE), ????? ??????? ?????????????? ???????????? ??..
  4. ???????? ?????????????? ????? ???, ????? ????????????? ??-??. ?? ???????? ??? ?? ?? ??-?? ??????? ?????
  5. ??? ??? ????? ????? ???? ???? ??, ?? ????? ??????? ?????????? ????????????? ??..
  6. ??? ????? ??? WelcomeAddIn ???? ?? ??? AddInDesigner1 ?? ????????? ?? ??? ??????
  7. ?????????? ???????? ??,UserForm??? UserForm ???????? ???? ?? ????
  8. ????? ?? ???? ???? ?? ??? ???? ??? ?? ???? UserForm.
  9. ??? ????? ??? ????? ?????? ??? ????? ?? ??? ???? ?? ??? ???????? ?? ????????? ????????? ????:
    ?? ?????? ?? ??????? ?????? ?????? ?? ??????? ????
    ???????????Value:
    ???????lblMessage
    ?????????????
    ?????14pt
    AutoSizeTrue
    CommandButton???cmdOK
    ??????OK
    UserForm???frmWelcome

  10. ?????????? ???????? ??,??????????? ???? ??????? ???????? ???? ???? ?? ????
  11. ????? ???????? ?? ??????? ?? declaration ???? ??????? ??? ??????:
    Public gstrUserName As String
    'This variable will be used to store the name of the user as defined
    'in the Options dialog boxes (from the Tools menu) in Word and Excel.
    					
  12. ??????? ??? ??? ????????? ?? ????????? ??? ????? ?? ??? ????? ??? ??????DisplayForm??????? ??????? ?? ????????? ????:
    Public Sub DisplayForm()
      frmWelcome.Show vbModal
    End Sub
    					
  13. FrmWelcome ??????? ?? ??? ??? ????? ??? ?????, ?? ????? ??? ??????UserForm_Initialize???? ?????? ???????? ?? ?? ??? concatenate ???? ?? ??? ?????:
    lblMessage.Caption = lblMessage.Caption & " " & gstrUserName
    					
  14. ????? ??? ??????????? ????,CommandButton ?? ??? ?????cmdOK??????? ?? ????? ????: ???? ?? ???
    Unload me
    					

??-?? ??????? ?? ??? ????????? ????

Designer ?? ????? ?? ????? ????? ??-?? ??????? ???? ???? ?? Microsoft Excel ??????? ???? ?? ???, ????? ????? ?? ???? ????:
  1. ????????? ???????????, ??? ??-?? ??????? ?? ????? ?? ??? ??? ?? ??? ????? ?????
  2. ????? ?????????????? designer ?? ????? ?????? ??? ????? ?? ??? ???? ?? ??? designer ?? ??? ?????????:
    ?? ?????? ?? ??????? ?????? ?????? ?? ??????? ????
    ???Value:
    AddIn ??????? ?? ???FunFormMessage
    AddIn ??????? ??? ?? ?? Excel ?? ??? ??????? ???
    ?????????Microsoft Excel
    ????????? ?? ???????Microsoft Excel 10.0
    ????????? ??? ????????????????

IDTExtensibility2 ????? ??????????? ????

  1. ??????????? ??,???:designer ?? ???? ??? ??????? ??????
  2. ??????????? ??,??????, ?? Microsoft Excel ???????? ?? ??? ?? ?????? ??? ??????????
  3. ??????????????????-???? ???? ???, ????? ????AddinInstance. ??????? ??? 1 ?? ??? ?? ????.?????-???? ???? ???, ????? ????OnConnection.

    ?? ????? ??? ?? ?? ????? ???? ??-?? ????????? ????? ???? ?? ??? ???????? ?? ?? ??? ????????? ????? ?? ??? ?????? ???? ?? ??? CommandBar ??? ????? ?? ??? ?????? ???
  4. ????? ??? ??????AddinInstance_OnConnection?????????? ??? ?? ??????? ?? ??? ?????? ???? ?? ??? ????? ?????????strUserName?? ??? ???? ?? ???DisplayForm?? ??? 1 ?? ??? ?? ????.:
    gstrUserName = Application.UserName
    DisplayForm
    					
  5. VBE ??? ????? ??????????, ?? ????????? Welcome.vba ????

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

?? ????????? ??? ?? ??? Microsoft Word ??? ???? ??????????? ?? ??????????? ???? ?? ??? ??? ????? designer.
  1. VBE ??? ????? ??-?? ????????? ?? ?????? AddInProject2 ?? ???????? ??? ?? ???? ?? ???
  2. ????????? ??????????? ??? ??? ?????? ??????-??????? (??????? ???AddInDesigner1) ???? ?????? ??-?? ????????? ???? ????????? ??? ?? designers ?? ??????
  3. ????????? ???????????, ??? ???? ?????AddInProject2?? ????-????? ????, ?? ???? ???????????? ??? ????????????? ???? ??? ????? ??????? ???
  4. ?? ???? ????? ????? ??????? ?? ????
    ????????? AddInProject2 ??????? ???? ??? ??? ???? ?? ??? ?????? ????? ????
    ????? ????,????.
  5. Designer ?? ????????? ???? ?? ??? ????? ?? ????????? ????Word 10?????? ????????? ?? ??? ??? ?? ?? ??? ???? ?? ????????????.
  6. ??? Word designer ?? ???? ?? ??? ????? ??? ??????AddinInstance_OnConnection????? ?????????, ?? Excel designer ?? ??? ???? ????? ??? ?? ???? ??OnConnection?????:
    gstrUserName = Application.UserName
    DisplayForm
    					

??-?? ???? ????

  1. ??? ?? ?????, ??? ?? ??? ??????? ????? ????? ??????
  2. VBE ??? ????? ????????????? ?? ???????????????? ??-?? ?? ????? ?? ??? ???
  3. Microsoft Excel ??????? ????? ????????? ??????? ???? ??, ?? ?? ???? ??????? ?? ??? ?? ????? ????? ?? ??? ???? ???? Click the option to start an application, and browse to Excel.exe. If this dialog box does not appear, click????????? ????? ????,????????????? ????-????? ????, ?? ???? ???Microsoft Excelto start Excel. Your UserForm should appear.
  4. If the COM Add-In Manager is not already available, add theCOM ??-??command to a toolbar as follows:
    1. ????? ????????????? ??,???????? ????.
    2. ????????????? ????????? ?????, ??????tab, drag theCOM ??-??command from the?????category onto a toolbar or onto the????????? ??.CommandBarPopup???????? ???
  5. ????? ????COM ??-??command bar to display the COM Add-In Manager (CAM). The list in the CAM displays all of the add-ins that are loaded.
  6. To test theOnConnectionevent, clear the???????Add-In check box in the CAM, and then clickOK. Redisplay the CAM, select the??????????????? ?? ????? ?? ??? ????? ????, ?? ???? ???OK. The UserForm should appear again.
  7. Close the host application (either Word or Excel), and clickStop Project???????menu in the VBE to stop running the project.

Verify That the Add-In Works

Now you can compile the add-in and verify that it works on another computer.
  1. Save the project in the VBE. This is your editable version. The compiled state does not allow you to make modifications.
  2. ?????????? ??,Make Welcome.DLL.
  3. ?????regsvr32command to register the DLL as follows:
    1. Windows ????????????? ??,?????.
    2. ????????????? ????? ???, ????? ??? ???? ????:
      regsvr32??> \Welcome.DLL
      ??????> DLL ???? ?? ??? ????? ?????? ?? ???
  4. ????? ????,OKDLL ?? ??????? ?? ?????? ???? ???? ?? ????
  5. Excel ??/?? Word ?? ?????? ???? UserForm ????? ???? ?????? ??? ?? ???? UserForm ? ????, ?? ????? ????COM AddIns???????????, ?? ???? ??? ?? ??? ?????????????? ?????.
???:: DLL ?? ?????? ???? ?? ??? easiest ????? ????? ?? ????????? ??????? ?? ????? ???? ?? ??? ???

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

  • ?? ????????? ???? ?? ?? ??-?? ?? ??? ??? ?????? ?? ??? ???, ???? ??? ?????? ?????? ?? ???, ??? ????OnConnection????? manipulates ????????? ?? ??????? ???? ??, ???? ?????????? ?? ???????? ?? ???? (??????) ???????? ????? ??????
  • ???? careful UserForms ?? ????? ???? ??? ??? ?????????? ?? ????????? ????? ????? ???? ??, ??, ?? ?? ?? ?? ??????? ??? ????? ????????? ?? ???? ???? ??? ?? ??????? ?????????? ????? ?? ?? ???? ??? ???? ????, ?? ???? ??????? ???? ?? ?????? ?? overcome ???? ?? ???? ????? ?? ??? ??????? ????, ?? ?????vbModal???????? follows ?? ??? ???:
    frmMyUserForm.Show vbModal
    						
    ????? ?? ??? ?????? ??? ???? ?? ??? ???? ?? ?????? ?? ?????? ???, ?? ??? 12 ??? ??? ?????Create an Add-In Project????

??????

Refer to the \Samples\Working with AddIns\VBA_COM_AddIn folder on the Office XP Developer CD for an AddIn template.

For additional information about creating CommandBar buttons, visit the following Microsoft Developer Network (MSDN) Web site:
http://msdn.microsoft.com/en-us/library/aa140930.aspx

???

???? ID: 306130 - ????? ???????: 04 ?????? 2010 - ??????: 2.0
???? ???? ???? ??:
  • Microsoft Office XP Developer Edition
??????: 
kbhowtomaster kbmt KB306130 KbMthi
???? ?????? ????????
??????????: ?? ???? ?? ???? ??????? ?? ????? ?? Microsoft ????-?????? ?????????? ?????? ?????? ???? ??? ??. Microsoft ???? ??? ????-???????? ?? ????-???????? ????? ?????? ?? ???? ???????? ???? ?? ???? ????? ????? ??? ?? ??? ?????? ?? ???? ???? ???? ??? ????? ??. ???????, ????-???????? ???? ????? ???? ???? ???? ???. ?????, ????????, ?????-???? ?? ??????? ?? ???????? ?? ???? ???, ???? ?? ??? ?????? ???? ???? ??? ????? ??? ?? ???? ??. Microsoft ??????? ??? ???? ?? ?????? ?? ??????????, ????????? ?? ??? ?????? ?? ???? ????? ?? ???? ???????? ?? ??? ???? ????? ?? ??? ????????? ???? ??. Microsoft ????-?????? ?????????? ?? ????? ?????? ?? ?? ??? ??.
?????????? ?? ??????? ????????? ??????? ??:306130

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

 

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