使用 Visual Studio 2015 开发 MS Access 2016 AddIn (Ribbon/VSTO) [英] Develop MS Access 2016 AddIn (Ribbon / VSTO) with Visual Studio 2015

查看:24
本文介绍了使用 Visual Studio 2015 开发 MS Access 2016 AddIn (Ribbon/VSTO)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

希望你能帮助我.我期待使用 Visual Studio 2015(作为 VSTO 的 Ribbon-Bar)对我的第一个 MS Access AddIn 进行编程,但还没有开始,我不得不停下来.Visual Studio 为几乎所有办公产品提供模板,但 MS Access 除外.我听说可以更改"例如 Excel VSTO 模板,以便它可以用于开发 MS Access 功能区.有谁知道如何处理这个问题的好说明?您如何为 MS Access 开发 VSTO?

感谢您的帮助

解决方案

有这方面的教程.我没试过,不知道它是否有效,但听起来很有希望.

这是多汁的部分.


<块引用>

  1. 要开始构建 Access 加载项,我可以创建一个 Word(或 InfoPath、PowerPoint、Project 或 Visio)加载项(Excel 或 Outlook 也可以使用,但它们有额外的冗余主机特定代码).

  2. 然后,我将在 COM 选项卡上添加对 Microsoft Access 对象库的引用(这也会引入对 ADODB 和 DAO 的引用).它还引入了 Microsoft.Office.Core.dll,它复制了默认情况下已经引用的 Office.dll - 所以我将删除这两个副本之一.

  3. 在解决方案资源管理器中,我可以选择项目并单击显示所有文件"按钮.这使得打开 ThisAddIn.Designer.cs 文件变得更容易——在这里我可以将 Application 字段的声明和初始化从 M.O.I.Word.Application 更改为 M.O.I.Access.Application.请注意,此步骤会更改自动生成的文件:该文件通常不会重新生成,但如果我损坏了项目,则可能会重新生成(重点是如果重新生成文件,我的手动更改将丢失):

//内部Microsoft.Office.Interop.Word.Application 应用程序;内部 Microsoft.Office.Interop.Access.Application 应用程序;//this.Application = this.GetHostItem(typeof(Microsoft.Office.Interop.Word.Application), "Application");this.Application = this.GetHostItem(typeof(Microsoft.Office.Interop.Access.Application), "Application");

<块引用>

  1. 这就是所有的代码更改.现在进行项目变更.有两种方法可以进行这些更改——通过 IDE 以覆盖或计数器默认设置的方式;或者通过直接手动编辑 .csproj 文件来替换默认设置.让我们看看这两种方法:首先通过 IDE,然后手动.

  2. 首先,我将更改项目属性 |调试 |启动动作,为启动外部程序",并指定Access的路径,例如:

    C:Program Files (x86)Microsoft OfficeOffice12MSACCESS.EXE

  3. 然后,我将创建一个与加载项解决方案同名的 .reg 文件,并将其放入解决方案文件夹中.此 reg 文件用于为 Access 注册加载项(并为 Word 取消注册).下面列出的示例 reg 文件只是标准 VSTO 构建任务对每种加载项类型所做的工作的转储,并带有附加行.附加行(下面的第一个 reg 条目)只是删除了构建任务为 Word 放入的条目.Word 和 Access 的其余条目相同,唯一的变化是将Word"替换为Access":

Windows 注册表编辑器 5.00 版[-HKEY_CURRENT_USERSoftwareMicrosoftOfficeWordAddinsMyAddIn][HKEY_CURRENT_USERSoftwareMicrosoftOfficeAccessAddinsMyAddIn]描述"=MyAddIn""FriendlyName"="MyAddIn""LoadBehavior"=dword:00000003"清单"="C:\Temp\MyAddIn\bin\Debug\MyAddIn.vsto|vstolocal"

<块引用>

  1. 在项目属性中 |构建事件,我添加了一个构建后事件命令行来将 .reg 文件合并到注册表中:

    regedit/s "$(SolutionDir)$(SolutionName).reg"

  2. 就是这样.我现在可以按 F5 来构建解决方案:这将为 Access 注册加载项,并在加载加载项的情况下运行 Access 进行调试.

  3. 请注意,不是将 Debug 属性设置为外部程序(上面的第 4 步),我可以直接修改 .csproj 文件,将 Word 设置为 Access.例如,更改此:

<块引用>

…到这个:

<块引用>

请注意,如上所示,更改值会更改解决方案资源管理器中使用的图标.

  1. 我还可以更改元素的 Name 值以更改解决方案资源管理器中 ThisAddIn.cs 的父节点的名称.改变这个:

<HostItem Name="ThisAddIn" Code="ThisAddIn.cs" CanonicalName="AddIn" CanActivate="false" IconIndex="1" Blueprint="ThisAddIn.Designer.xml" GeneratedCode="ThisAddIn.Designer.cs"/></主机>

<块引用>

…到这个:

<HostItem Name="ThisAddIn" Code="ThisAddIn.cs" CanonicalName="AddIn" CanActivate="false" IconIndex="1" Blueprint="ThisAddIn.Designer.xml" GeneratedCode="ThisAddIn.Designer.cs"/></主机>

<块引用>

  1. 此外,注册由元素值决定.因此,与其将 .reg 文件设置为构建后任务(上面的步骤 5-6),我还可以直接编辑 .csproj 以进行更改:

Word

<块引用>

...至此:

访问

Hope you can help me. I am looking forward to programming my first MS Access AddIn with Visual Studio 2015 (a Ribbon-Bar as VSTO), but not having started I have to stop already. Visual Studio provides templates for almost every office product, but MS Access. I heard it is possible to "change" for example the Excel VSTO-Template so it can be used to develop an MS Access Ribbon. Does anyone know a good instruction how to handle this? How are you developing VSTO for MS Access?

Thanks for your help

解决方案

There exists a tutorial for this. I haven't tried it, don't know if it works, but it sounds promising.

Here are the juicy bits.


  1. To start building an Access add-in, I could create a Word (or InfoPath, PowerPoint, Project or Visio) add-in (Excel or Outlook would also work, but they have additional redundant host-specific code).

  2. Then, I'll add a reference to the Microsoft Access Object Library, on the COM tab (this also pulls in references to ADODB and DAO). It also pulls in Microsoft.Office.Core.dll, which duplicates the Office.dll already referenced by default - so I'll delete one of these two duplicates.

  3. In Solution Explorer, I can select the project and click the "show all files" button. This makes it easier to open the ThisAddIn.Designer.cs file – here I can change the declaration and initialization of the Application field from M.O.I.Word.Application to M.O.I.Access.Application. Note that this step changes a file that is auto-generated: the file is not normally re-generated, but can be if I corrupt the project (the point being that my manual changes will be lost if the file is re-generated):

//internal Microsoft.Office.Interop.Word.Application Application;
internal Microsoft.Office.Interop.Access.Application Application;

//this.Application = this.GetHostItem<Microsoft.Office.Interop.Word.Application>(typeof(Microsoft.Office.Interop.Word.Application), "Application");
this.Application = this.GetHostItem<Microsoft.Office.Interop.Access.Application>(typeof(Microsoft.Office.Interop.Access.Application), "Application");

  1. That's all the code changes. Now for the project changes. There are two ways to do these changes – through the IDE in a way that overrides or counters the default settings; or by manually editing the .csproj file directly, to replace the default settings. Let's look at both approaches: first through the IDE, then manually.

  2. First, I'll change the Project Properties | Debug | Start action, to "Start external program", and specify the path to Access, for example:

    C:Program Files (x86)Microsoft OfficeOffice12MSACCESS.EXE

  3. Then, I'll create a .reg file with the same name as my add-in solution, and put it in the solution folder. This reg file is used to register the add-in for Access (and unregister it for Word). The example reg file listed below is simply a dump of what the standard VSTO build task does for each add-in type, with an additional line. The additional line (the first reg entry below) simply removes the entry that the build task puts in for Word. The remaining entries are identical for Word and Access, with the only changing being to replace "Word" with "Access":

Windows Registry Editor Version 5.00
[-HKEY_CURRENT_USERSoftwareMicrosoftOfficeWordAddinsMyAddIn]
[HKEY_CURRENT_USERSoftwareMicrosoftOfficeAccessAddinsMyAddIn]
"Description"="MyAddIn"
"FriendlyName"="MyAddIn"
"LoadBehavior"=dword:00000003
"Manifest"="C:\Temp\MyAddIn\bin\Debug\MyAddIn.vsto|vstolocal"

  1. In Project Properties | Build Events, I add a Post-build event commandline to merge the .reg file into the registry:

    regedit /s "$(SolutionDir)$(SolutionName).reg"

  2. That's it. I can now press F5 to build the solution: this will register the add-in for Access, and run Access for debugging with the add-in loaded.

  3. Note that instead of setting the Debug property to an external program (step 4 above), I could modify the .csproj file directly, to set the from Word to Access. For example, change this:

<ProjectProperties HostName="Word"
  HostPackage="{D2B20FF5-A6E5-47E1-90E8-463C6860CB05}" OfficeVersion="12.0" VstxVersion="3.0"
  ApplicationType="Word" Language="cs" TemplatesPath="" DebugInfoExeName="#SoftwareMicrosoftOffice12.0WordInstallRootPath#WINWORD.EXE"
  AddItemTemplatesGuid="{147FB6A7-F239-4523-AE65-B6A4E49B361F}" />

… to this:

<ProjectProperties HostName="Access"
  HostPackage="{D2B20FF5-A6E5-47E1-90E8-463C6860CB05}" OfficeVersion="12.0" VstxVersion="3.0"
  ApplicationType="Access" Language="cs" TemplatesPath="" DebugInfoExeName="#SoftwareMicrosoftOffice12.0AccessInstallRootPath#MSACCESS.EXE"
  AddItemTemplatesGuid="{147FB6A7-F239-4523-AE65-B6A4E49B361F}" />

Note that changing the value, as show above, changes the icons used in the Solution Explorer .

  1. I could also change the element's Name value to change the name of the parent node for the ThisAddIn.cs in the Solution Explorer. Change this:

<Host Name="Word" GeneratedCodeNamespace="MyAddIn" IconIndex="0">
  <HostItem Name="ThisAddIn" Code="ThisAddIn.cs" CanonicalName="AddIn" CanActivate="false" IconIndex="1" Blueprint="ThisAddIn.Designer.xml" GeneratedCode="ThisAddIn.Designer.cs" />
</Host>

… to this:

<Host Name="Access" GeneratedCodeNamespace="MyAddIn" IconIndex="0">
  <HostItem Name="ThisAddIn" Code="ThisAddIn.cs" CanonicalName="AddIn" CanActivate="false" IconIndex="1" Blueprint="ThisAddIn.Designer.xml" GeneratedCode="ThisAddIn.Designer.cs" />
</Host>

  1. Also, registration is determined by the element value. So, instead of setting up a .reg file as a post-build task (steps 5-6 above), I could edit the .csproj directly to change this:

<OfficeApplication>Word</OfficeApplication>

…to this:

<OfficeApplication>Access</OfficeApplication>

这篇关于使用 Visual Studio 2015 开发 MS Access 2016 AddIn (Ribbon/VSTO)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆