处理另一个加载项的提示 [英] Handling the prompts of another Add-In

查看:86
本文介绍了处理另一个加载项的提示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码是我创建的Excel加载项的一部分,将创建我们打开的当前数据提取的文件名.

The following code, which is part of an Excel Add-In that I created, will create a file name of the current data extract that we have open.

Sub ExtractSave()
'
If InStr(LCase$(ActiveWorkbook.name), "extract") > 0 Then
    Exit Sub
Else
    Dim MyDir As String, fn As String
    MyDir = CreateObject("WScript.Shell").SpecialFolders("MyDocuments") & "\Extract Files" ' change this to valid path
    If Len(Dir(MyDir, vbDirectory)) = 0 Then MkDir MyDir
    fn = MyDir & "\Extract - " & Format(Now, "mm-dd-yyyy hh_mm")
    ActiveWorkbook.SaveAs Filename:=fn, FileFormat:=xlOpenXMLWorkbook
End If

End Sub

当我关闭工作簿时,确实需要进行保存,因为将对工作簿进行更改.所有这些都很好.问题在于该公司具有一个.COM加载项,该加载项必须在所有文档上运行.它用特定的安全级别标识符标记文档页脚.虽然我不需要绕过此操作,但我想知道是否有可能编写在此框出现时可以复制按回车键的代码?有两个按钮,取消.弹出窗口上的默认按钮为.我确实尝试添加

When I close the workbook, it does require a save to occur as changes will be made to the workbook. All of this works just fine. The issue is that the company has a .COM Add-In that is required to run on all documents. It labels the document footer with a specific security level identifier. While I do not need to bypass this, I would like to know if it is possible to write code that will replicate hitting enter when this box appears? There are two buttons, Yes and Cancel. The default button is Yes on the popup. I did try adding

Application.DisplayAlerts = False
If Me.Saved = False Then Me.Save
Application.DisplayAlerts = True

进入Workbook_BeforeClose私有Sub,但是操作仍然出现.另外,如果我是对的,那么这部分代码对于已保存的工作簿将不起作用,因为它是在外接程序中运行的.

into the Workbook_BeforeClose private Sub, but the op still appeared. Also, if I am correct, this bit of code will not work for the Saved workbook because this is running from within the Add-In.

对于该特定问题,我找不到任何等效的信息,因此,我们将不胜感激.另外,我不知道还有哪些其他信息对您寻求解决方案有帮助,所以请不要因为我错过了一些事情而投下反对票.

I have not been able to find any equivalent information for this particular issue, so any help would be appreciated. Also, I do not know what other information would be useful in your assistance to finding a solution, so please ask and do not down vote because I missed something.

事件顺序:

  1. 将数据导入新工作簿
  2. 运行ExtractSave例程
  3. 请参阅.COM加载项弹出窗口(需要按是"按钮,是"是 默认按钮)
  4. 用户在工作簿上执行职责
  5. 单击关闭
  6. 提示将更改保存到工作簿中(再次,默认值为YES, 需要这个点击")
  7. 再次看到.COM加载项弹出窗口(需要按YES按钮,是 是默认按钮)
  1. Import data into new workbook
  2. Run ExtractSave routine
  3. See the .COM addin popup (need to have YES button pressed, YES is the default button)
  4. User performs duties on the workbook
  5. Click on close
  6. prompted to Save the changes to the workbook (again, default is YES, need this "clicked")
  7. See the .COM addin popup again(need to have YES button pressed, YES is the default button)

在保存工作簿时,可以使用哪些VBA代码自动单击.COM加载项的是"按钮?

What VBA code is available to automatically click on the YES buttons for the .COM add-in while saving the workbook?

推荐答案

来自评论:

在第一个保存事件(OP中列表中的#2)发生时,在ActiveWorkbook.SaveAs Filename:=fn, FileFormat:=xlOpenXMLWorkbook行之前添加Application.SendKeys ("~")即可.

Adding Application.SendKeys ("~") before this line ActiveWorkbook.SaveAs Filename:=fn, FileFormat:=xlOpenXMLWorkbook worked when the first save event (#2 from the list in the OP) occurred.

对于#7 .COM加载项弹出窗口,在Workbook_BeforeSave事件中添加Application.SendKeys ("~")并没有帮助(我希望有人可以帮助我们修复该问题):

And For #7 .COM addin popup, adding Application.SendKeys ("~") in Workbook_BeforeSave event didn't help (I hope someone can help us to fix it):

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)

     SendKeys "~"  

End Sub

这篇关于处理另一个加载项的提示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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