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
Excel 作为从单元格中提取的变量?@tim粘贴时,这将使OERN处于活动状态而不会出错?@chrisneilsen-非常确定OERN不会“向上”移动到调用代码,但我会加倍-check@tim并不意味着它“向上移动”(它没有)。如果这是子组件的全部内容,则此处没有问_Excel_Vba - Fatal编程技术网

Excel 作为从单元格中提取的变量?@tim粘贴时,这将使OERN处于活动状态而不会出错?@chrisneilsen-非常确定OERN不会“向上”移动到调用代码,但我会加倍-check@tim并不意味着它“向上移动”(它没有)。如果这是子组件的全部内容,则此处没有问

Excel 作为从单元格中提取的变量?@tim粘贴时,这将使OERN处于活动状态而不会出错?@chrisneilsen-非常确定OERN不会“向上”移动到调用代码,但我会加倍-check@tim并不意味着它“向上移动”(它没有)。如果这是子组件的全部内容,则此处没有问,excel,vba,Excel,Vba,作为从单元格中提取的变量?@tim粘贴时,这将使OERN处于活动状态而不会出错?@chrisneilsen-非常确定OERN不会“向上”移动到调用代码,但我会加倍-check@tim并不意味着它“向上移动”(它没有)。如果这是子组件的全部内容,则此处没有问题。如果粘贴失败,则下一个OnAction行不会失败?@TimWilliams不会出现问题。这就是让人如此困惑的地方,事实上没有什么是失败的,我只是不断地得到一个错误,说它失败了。因此,如果粘贴失败,那么OnAction也会失败,但据我所知,它


作为从单元格中提取的变量?@tim粘贴时,这将使OERN处于活动状态而不会出错?@chrisneilsen-非常确定OERN不会“向上”移动到调用代码,但我会加倍-check@tim并不意味着它“向上移动”(它没有)。如果这是子组件的全部内容,则此处没有问题。如果粘贴失败,则下一个
OnAction
行不会失败?@TimWilliams不会出现问题。这就是让人如此困惑的地方,事实上没有什么是失败的,我只是不断地得到一个错误,说它失败了。因此,如果粘贴失败,那么OnAction也会失败,但据我所知,它从未真正失败过。
Sub CopyAllShapes()
Dim ws As Worksheet

' Sets the non-generated worksheets as an array
nSheets = Array("EXAMPLE", "Weekly Totals", "Menu")

' Copies the Picture from the EXAMPLE sheet to all worksheets not in the array and then assigns a 
' seperate Macro called "Export" to the picture on each of these sheets.
For Each ws In ActiveWorkbook.Worksheets
    If Not IsNumeric(Application.Match(ws.Name, nSheets,0)) Then
        Sheets("EXAMPLE").Shapes("Picture 1").Copy
        ws.Range("J62").PasteSpecial
        ws.Shapes("Picture 1").OnAction = "Export"
    End If
Next ws

Application.CutCopyMode = xlCopy
End Sub
ws.Range("J62").PasteSpecial
'paste problem fix
Sub PastePicRetry(rng As Range)
    Dim i As Long
    Do While i < 20
        On Error Resume Next
        rng.PasteSpecial
        If Err.Number <> 0 Then
            Debug.Print "Paste failed", i
            DoEvents
            i = i + 1
        Else
            Exit Do
        End If
        On Error GoTo 0
        i = i + 1
    Loop
End Sub
Sub CopyAllShapes()
Dim ws As Worksheet

' Sets the non-generated worksheets as an array
nSheets = Array("EXAMPLE", "Weekly Totals", "Menu")

' Copies the Picture from the EXAMPLE sheet to all worksheets not in the array and then assigns a 
' seperate Macro called "Export" to the picture on each of these sheets.
For Each ws In ActiveWorkbook.Worksheets
    If Not IsNumeric(Application.Match(ws.Name, nSheets,0)) Then
        Sheets("EXAMPLE").Shapes("Picture 1").Copy
    On Error Resume Next
        ws.Range("J62").PasteSpecial
    On Error Goto 0
        ws.Shapes("Picture 1").OnAction = "Export"
    End If
Next ws

Application.CutCopyMode = xlCopy
End Sub
Const MaxRetries AS Long = 3

Sub CopyAllShapes()
    Dim ws As Worksheet
    Dim TimesRetried As Long

    ' Sets the non-generated worksheets as an array
    nSheets = Array("EXAMPLE", "Weekly Totals", "Menu")

    ' Copies the Picture from the EXAMPLE sheet to all worksheets not in the array and then assigns a 
    ' seperate Macro called "Export" to the picture on each of these sheets.
    For Each ws In ActiveWorkbook.Worksheets
        If Not IsNumeric(Application.Match(ws.Name, nSheets,0)) Then
            TimesRetried = 0
CopyExampleShape:
            On Error Resume Next
            Sheets("EXAMPLE").Shapes("Picture 1").Copy
            ws.Range("J62").PasteSpecial
            'If the Copy/Paste fails, retry
            If Err Then
                On Error GoTo -1 'Clear the Error
                'Don't get stuck in an infinite loop
                If TimesRetried < MaxRetries Then
                    'Retry the Copy/paste
                    TimesRetried = TimesRetried + 1
                    DoEvents
                    GoTo CopyExampleShape
                End If
            End If
            On Error GoTo 0
            ws.Shapes("Picture 1").OnAction = "Export"
        End If
    Next ws

    Application.CutCopyMode = xlCopy
End Sub