Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vba 除非禁用限制,否则无法从Excel复制并粘贴到表单编辑受限Word文档_Vba_Excel_Ms Word_Copy Paste - Fatal编程技术网

Vba 除非禁用限制,否则无法从Excel复制并粘贴到表单编辑受限Word文档

Vba 除非禁用限制,否则无法从Excel复制并粘贴到表单编辑受限Word文档,vba,excel,ms-word,copy-paste,Vba,Excel,Ms Word,Copy Paste,我正在将Excel单元格内容复制到Form Edit restricted 2010 Word文档上的书签中,但它仅在保护关闭时才会粘贴 代码我目前必须再次打开保护后出错。正确的代码是什么 有没有一种方法可以在不关闭保护的情况下进行复制和粘贴 第二个问题是,当文本粘贴到书签时,如果在文档中手动输入,则字体为红色,而它是黑色的。“默认值”一词设置为黑色,我将重置默认值以进行良好测量。在新文档中输入是黑色的,但是,当Word打开时,字体图标显示为红色,即使选中默认值,它仍然显示为黑色。我是否可以在V

我正在将Excel单元格内容复制到Form Edit restricted 2010 Word文档上的书签中,但它仅在保护关闭时才会粘贴

代码我目前必须再次打开保护后出错。正确的代码是什么

有没有一种方法可以在不关闭保护的情况下进行复制和粘贴

第二个问题是,当文本粘贴到书签时,如果在文档中手动输入,则字体为红色,而它是黑色的。“默认值”一词设置为黑色,我将重置默认值以进行良好测量。在新文档中输入是黑色的,但是,当Word打开时,字体图标显示为红色,即使选中默认值,它仍然显示为黑色。我是否可以在VBA中定义字体颜色以覆盖此问题,直到问题得到解决,或者您是否可以建议一种修复单词default的方法

Sub Arzbericht_Brandstetter()

' x - Defined Cell Names -  ARTBrandPATH   ,  ARTBrandDOC

'                               Excel          Word Bookmark
' x - Defined Cell Names -  ARZKrankenhaus       Text65


Dim wb As Workbook
Dim ws As Worksheet
Set wb = ActiveWorkbook
Set ws = ActiveSheet

Dim Wd As Object
Dim wdDoc As Object
Dim BrandstetterDoc As Object
Dim BrandstetterPath As String

Dim f As Boolean

BrandstetterPath = ActiveSheet.Range("ARTBrandPATH").Value & ActiveSheet.Range("ARTBrandDOC").Value & ".doc"  ' x

'    On Error Resume Next

Set BrandstetterDoc = GetObject(BrandstetterPath)

If BrandstetterDoc Is Nothing Then
    Set Wd = GetObject(, "Word.Application")
    If Wd Is Nothing Then
        Set Wd = CreateObject("Word.Application")
        If Wd Is Nothing Then
            MsgBox "Failed to start Word!", vbCritical
            Exit Sub
        End If
        f = True
    End If
    Set BrandstetterDoc = Wd.Documents.Open(BrandstetterPath)
    If BrandstetterDoc Is Nothing Then
        MsgBox "Failed to open Brandstetter Document!" & vbNewLine & _
                   " Check File Directory is correct", vbCritical
        If f Then
            Wd.Quit
        End If
        Exit Sub
    End If
    Wd.Visible = True
Else
    With BrandstetterDoc.Parent
        .Visible = True
        .Activate


'  Turn Protection OFF
        With ActiveDocument
            .Unprotect "xxxxx"
            .Protect wdAllowOnlyRevisions, , Password:="xxxxx"
        End With

        BrandstetterDoc.Bookmarks("Text65").Range.Text = ws.Range("ARZKrankenhaus").Value


'  Turn Protection ON   (Restricted Editing)
'           ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True

    End With
End If

End Sub

因为它是一个Formfield,而不仅仅是一个书签,我修改了下面的代码,解决了奇怪的红色字体问题。我现在可以复制到受保护的文档

From
BrandstetterDoc.Bookmarks("Text65").Range.Text = ws.Range("ARZKrankenhaus").Value
To
ActiveDocument.FormFields("Text65").Result = ws.Range("ARZKrankenhaus").Value