- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我注意到 Project 2007 具有允许将可撤消的操作放置在单个堆栈项或“撤消事务”中的功能。 For example:
Application.OpenUndoTransaction "Create 6 tasks"
Dim i As Integer
For i = 1 To 6
ActiveProject.Tasks.Add "UndoMe " & i
Next
Application.CloseUndoTransaction
这意味着用户可以在一次撤消操作中撤消所有操作,而不是 6 次。
这在 Word 和/或 Excel 中实现会很棒,因为我正在 VSTO 中做一些同时进行多项更改的操作,如果用户必须单击“撤消”,这对用户来说会有点烦人如果他们犯了错误,就多说几次。尽管这些特定功能似乎不存在,但有人知道是否/如何以某种方式完成此操作?
最佳答案
您可以通过覆盖 VBA 中的撤消和重做命令例程来模拟 Word 中的事务行为(不过,我认为单独使用 VSTO 不可能覆盖内置 Word 命令)。通过添加书签来标记事务的开始,通过删除书签来标记事务的结束。
当调用undo时,我们检查事务标记书签是否存在并重复undo直到标记消失。重做的工作方式相同。该机制支持对文档内容所做的所有修改的事务撤消/重做。但是,为了允许撤消/重做对文档属性的修改,需要使用 SetCustomProp 宏来实现特殊机制。文档属性不应直接设置,而只能通过此宏设置。
更新:我忘了明确提及,这种方法仅适用于键盘快捷键和菜单命令,单击工具栏按钮仍然会执行单步撤消。因此,我们决定用自定义按钮替换工具栏按钮。该代码已在 Word 2003 中使用了相当长一段时间(尚未在 Word 2007 中进行测试,因此请做好意外惊喜的准备;)
Option Explicit
' string constants for Undo mechanism
Public Const BM_IN_MACRO As String = "_InMacro_"
Public Const BM_DOC_PROP_CHANGE As String = "_DocPropChange_"
Public Const BM_DOC_PROP_NAME As String = "_DocPropName_"
Public Const BM_DOC_PROP_OLD_VALUE As String = "_DocPropOldValue_"
Public Const BM_DOC_PROP_NEW_VALUE As String = "_DocPropNewValue_"
'-----------------------------------------------------------------------------------
' Procedure : EditUndo
' Purpose : Atomic undo of macros
' Note: This macro only catches the menu command and the keyboard shortcut,
' not the toolbar command
'-----------------------------------------------------------------------------------
Public Sub EditUndo() ' Catches Ctrl-Z
'On Error Resume Next
Dim bRefresh As Boolean
bRefresh = Application.ScreenUpdating
Application.ScreenUpdating = False
Do
If ActiveDocument.Bookmarks.Exists(BM_DOC_PROP_CHANGE) Then
Dim strPropName As String
Dim strOldValue As String
strPropName = ActiveDocument.Bookmarks(BM_DOC_PROP_NAME).Range.Text
strOldValue = ActiveDocument.Bookmarks(BM_DOC_PROP_OLD_VALUE).Range.Text
ActiveDocument.CustomDocumentProperties(strPropName).Value = strOldValue
End If
Loop While (ActiveDocument.Undo = True) _
And ActiveDocument.Bookmarks.Exists(BM_IN_MACRO)
Application.ScreenUpdating = bRefresh
End Sub
'-----------------------------------------------------------------------------------
' Procedure : EditRedo
' Purpose : Atomic redo of macros
' Note: This macro only catches the menu command and the keyboard shortcut,
' not the toolbar command
'-----------------------------------------------------------------------------------
Public Sub EditRedo() ' Catches Ctrl-Y
Dim bRefresh As Boolean
bRefresh = Application.ScreenUpdating
Application.ScreenUpdating = False
Do
If ActiveDocument.Bookmarks.Exists(BM_DOC_PROP_CHANGE) Then
Dim strPropName As String
Dim strNewValue As String
strPropName = ActiveDocument.Bookmarks(BM_DOC_PROP_NAME).Range.Text
strNewValue = ActiveDocument.Bookmarks(BM_DOC_PROP_NEW_VALUE).Range.Text
ActiveDocument.CustomDocumentProperties(strPropName).Value = strNewValue
End If
Loop While (ActiveDocument.Redo = True) _
And ActiveDocument.Bookmarks.Exists(BM_IN_MACRO)
Application.ScreenUpdating = bRefresh
End Sub
'-----------------------------------------------------------------------------------
' Procedure : SetCustomProp
' Purpose : Sets a custom document property
'-----------------------------------------------------------------------------------
Public Function SetCustomProp(oDoc As Document, strName As String, strValue As String)
Dim strOldValue As String
On Error GoTo existsAlready
strOldValue = ""
oDoc.CustomDocumentProperties.Add _
Name:=strName, LinkToContent:=False, Value:=Trim(strValue), _
Type:=msoPropertyTypeString
GoTo exitHere
existsAlready:
strOldValue = oDoc.CustomDocumentProperties(strName).Value
oDoc.CustomDocumentProperties(strName).Value = strValue
exitHere:
' support undo / redo of changes to the document properties
'On Error Resume Next
Dim bCalledWithoutUndoSupport As Boolean
If Not ActiveDocument.Bookmarks.Exists(BM_IN_MACRO) Then
ActiveDocument.Range.Bookmarks.Add BM_IN_MACRO, ActiveDocument.Range
bCalledWithoutUndoSupport = True
End If
Dim oRange As Range
Set oRange = ActiveDocument.Range
oRange.Collapse wdCollapseEnd
oRange.Text = " "
oRange.Bookmarks.Add "DocPropDummy_", oRange
oRange.Collapse wdCollapseEnd
oRange.Text = strName
oRange.Bookmarks.Add BM_DOC_PROP_NAME, oRange
oRange.Collapse wdCollapseEnd
oRange.Text = strOldValue
oRange.Bookmarks.Add BM_DOC_PROP_OLD_VALUE, oRange
oRange.Collapse wdCollapseEnd
oRange.Text = strValue
oRange.Bookmarks.Add BM_DOC_PROP_NEW_VALUE, oRange
oRange.Bookmarks.Add BM_DOC_PROP_CHANGE
ActiveDocument.Bookmarks(BM_DOC_PROP_CHANGE).Delete
Set oRange = ActiveDocument.Bookmarks(BM_DOC_PROP_NEW_VALUE).Range
ActiveDocument.Bookmarks(BM_DOC_PROP_NEW_VALUE).Delete
If Len(oRange.Text) > 0 Then oRange.Delete
Set oRange = ActiveDocument.Bookmarks(BM_DOC_PROP_OLD_VALUE).Range
ActiveDocument.Bookmarks(BM_DOC_PROP_OLD_VALUE).Delete
If Len(oRange.Text) > 0 Then oRange.Delete
Set oRange = ActiveDocument.Bookmarks(BM_DOC_PROP_NAME).Range
ActiveDocument.Bookmarks(BM_DOC_PROP_NAME).Delete
If Len(oRange.Text) > 0 Then oRange.Delete
Set oRange = ActiveDocument.Bookmarks("DocPropDummy_").Range
ActiveDocument.Bookmarks("DocPropDummy_").Delete
If Len(oRange.Text) > 0 Then oRange.Delete
If bCalledWithoutUndoSupport And ActiveDocument.Bookmarks.Exists(BM_IN_MACRO) Then
ActiveDocument.Bookmarks(BM_IN_MACRO).Delete
End If
End Function
'-----------------------------------------------------------------------------------
' Procedure : SampleUsage
' Purpose : Demonstrates a transaction
'-----------------------------------------------------------------------------------
Private Sub SampleUsage()
On Error Resume Next
' mark begin of transaction
ActiveDocument.Range.Bookmarks.Add BM_IN_MACRO
Selection.Text = "Hello World"
' do other stuff
' mark end of transaction
ActiveDocument.Bookmarks(BM_IN_MACRO).Delete
End Sub
关于.net - 我可以在 Word 或 Excel 中创建撤消事务吗? (VSTO),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/661269/
我有一个用于 Outlook 的 VSTO 加载项,当我必须提供 VSTO-Runtime 时需要这些信息 安装插件。 我已经找到了这个article描述先决条件,但我可以构建不符合此描述的案例: 文
我正在尝试在针对 3.5 框架和 Excel2007 使用 c# 的 VSTO 项目中使用 SpecialCells 方法。 这是我的代码: Excel.Worksheet myWs = (Excel
我们有一个 MS Word 插件,它当前使用并重命名 Word 中的插件选项卡(到 i-report)。 这样做的问题是,如果客户端安装了其他插件,其插件的功能区也会出现在 i-report 选项卡下
编辑:海报的答案是正确的,但包含内容应为 xmlns="http://schemas.microsoft.com/office/2009/07/customui"。作为副作用,XML 文件中定义的功能
我为 Outlook/Word/Excel/PowerPoint 创建了几个 VSTO 插件。当我构建它们然后启动相关程序时,加载项已安装并且运行良好。 当我尝试手动安装 DLL 时,在“Option
我正在为 Powerpoint 2010 构建一个 VSTO 加载项,加载项集的选项适用于当前打开的文件,而不是每个用户的配置。我可以将这些选项保存在当前文件中吗(我的意思是,将自定义 XML 添加到
这个问题在这里已经有了答案: 8年前关闭。 Possible Duplicate: How to troubleshoot a VSTO addin that does not load? 我有一个
我正在开发一个 PowerPoint C# VSTO 加载项。每当更改幻灯片的标题文本时,我希望能够捕获文本更改事件。 如何附加一个自定义事件处理程序,该处理程序会在标题文本更改时触发? 最佳答案 两
如何从插件中转到下一张/上一张幻灯片 最佳答案 由于 VSTO 几乎将 Interop 用于所有(并非所有),因此您可以将 MSDN 上的示例用于 VSTO 特定的解决方案。您要的是 SlideSho
这是错误: Error 2 Cannot assign to 'Activate' because it is a 'method group' Warning 1 Ambiguity
如何从 Microsoft Visual Studio 2010 中的 excel 加载项 vsto 作为特定单元格 B1 访问。 Globals.Sheet1.Range(“B3”).Value这不
有没有办法使用 VSTO 访问 PowerPoint 演示文稿中当前事件的幻灯片?如果我能获得当前事件的形状,那也很好。我知道如何遍历幻灯片/形状,但我找不到任何属性来确定幻灯片/形状是否处于事件状态
我们计划实现 Outlook-Addin (2007/2010)。我们的第一次尝试是使用 VSTO 2010 来完成,但我们想知道在这种情况下对客户端是否有一些特殊要求。 最佳答案 Office 20
我正在使用 VSTO 4 部署我的第一个 Visual Studio Tools for Office (VSTO) 加载项。 有一些不同的选项可用于安装加载项注册表项。它可以是 HKEY_CURRE
我正在尝试将 ListObject 从 .NET 3.5 Excel 2007 VSTO 工作簿保存到新工作表(完成),并将该新工作表保存到新工作簿(完成),而该工作簿不需要 VSTO 自定义文件(!
我正在尝试诊断为什么用 C#/VSTO 3.0/VS 2008 编写的 Outlook 插件在安装后无法加载。 该插件在我安装了 Visual Studio 2008 的开发计算机上运行得非常好。不过
办公自动化、VSTO 和 Open XML SDK 之间有什么区别?我们需要所有这些还是其中一些已经过时? 最佳答案 办公自动化是指使用 COM 互操作以编程方式操作 Office 程序(或更常见的是
我有一个 OneClick Deployed VSTO Addin,我已使用最新的 Verisign 代码签名证书 (PFX) 对其进行签名。我已经确认我在电话上通过 Verisign 支持正确签名
环境:VS 2010 | .net 3.5 |展望 2007 | VSTO 3 我有一个添加新消息类型的 outlook 插件(通过从 PostItem 继承)。我想在收到新邮件时触发 Outlook
我already know如何打开文件并从 Microsoft.Office.Interop.Excel 命名空间获取 Workbook。但是有没有办法从 Microsoft.Office.Tools
我是一名优秀的程序员,十分优秀!