问题描述
我在 word 中使用强制样式锁定保护工作表。我想制作一个宏,允许使用原始格式在文档中粘贴,并且只允许粘贴来自其他来源的文本。
我想让它看起来像:
Public Sub Pasting()
If "pasting within document = true" Then
Set aDoc = ActiveDocument
aDoc.Unprotect
Selection.PasteAndFormat Type:=wdFormatOriginalFormatting
aDoc.Protect wdAllowOnlyReading,UseIRM:=False,EnforceStyleLock:=True
Else
Selection.Paste 'it will remove formating anyway because of file being protected
End If
End Sub
不知道怎么处理,不知道怎么设计条件语句。 请帮忙,谢谢:)
解决方法
我尝试过类似下面的方法,但它也允许从另一个 Word 文档粘贴格式。我想避免它 - 只允许从当前文档粘贴格式。 也许有人知道如何修改它?
Private Declare PtrSafe Function GetClipboardOwner Lib "user32" () As Long
Public a As Long
Sub Document_open()
ActiveDocument.Paragraphs(1).Range.Copy
a = GetClipboardOwner
End Sub
'and
Private Declare PtrSafe Function GetClipboardOwner Lib "user32" () As Long
Public Sub Pasting()
If GetClipboardOwner = ThisDocument.a Then
Set aDoc = ActiveDocument
aDoc.Unprotect
Selection.PasteAndFormat Type:=wdFormatOriginalFormatting
aDoc.Protect wdAllowOnlyReading,UseIRM:=False,EnforceStyleLock:=True
Else
Selection.Paste
End If
End Sub