Dieses Forum nutzt Cookies
Dieses Forum verwendet Cookies, um deine Login-Informationen zu speichern, wenn du registriert bist, und deinen letzten Besuch, wenn du es nicht bist. Cookies sind kleine Textdokumente, die auf deinem Computer gespeichert werden. Die von diesem Forum gesetzten Cookies werden nur auf dieser Website verwendet und stellen kein Sicherheitsrisiko dar. Cookies aus diesem Forum speichern auch die spezifischen Themen, die du gelesen hast und wann du zum letzten Mal gelesen hast. Bitte bestätige, ob du diese Cookies akzeptierst oder ablehnst.

Ein Cookie wird in deinem Browser unabhängig von der Wahl gespeichert, um zu verhindern, dass dir diese Frage erneut gestellt wird. Du kannst deine Cookie-Einstellungen jederzeit über den Link in der Fußzeile ändern.

Excel2016-Die PasteSpecial-Methode des Range-Objektes konnte nicht ausgeführt werden
#1
Hallo,

aus dem Homeoffice heraus suche ich den Draht nach draußen und euren Rat.

Auf computer@office treten bei einem Makro zufällig folgende Laufzeitfehler auf, auf computer@HomeOffice nicht:

computer@office: Nachdem ich einige Male, mal mehr mal weniger häufig, auf Debuggen geklickt und mit F5 die Fortsetzung des Makros angestoßen habe, läuft das Makro schlussendlich doch ohne weitere Unterbrechungen durch.

Code:
xRg.PasteSpecial '** Laufzeitfehler '1004': Die PasteSpecial-Methode des Range-Objektes konnte nicht ausgeführt werden.

Code:
xRg.PasteSpecial '** Laufzeitfehler '1004': Microsoft Excel kann die Daten nicht einfügen.

Code:
Sub extract_userpicture_from_comments
    Dim rngZelle As Range
    Dim xRg As Range
    Dim visBool As Boolean
    Dim cmtTxt As String
    Dim i As Integer
   
    If ActiveSheet.Comments.Count = 0 Then
     MsgBox "No comments in entire sheet"
     Exit Sub
    End If

Application.CutCopyMode = False
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual

For Each rngZelle In Selection.Cells

    With rngZelle   
        rngZelle.Select
   
        If .Comment Is Nothing Then
        GoTo LabelA
        Else

            With .Comment           
               
                cmtTxt = .Text
                .Text Text:="" & Chr(10) & ""
                visBool = .Visible
                .Visible = True
                .Shape.CopyPicture _
                  Appearance:=xlScreen, Format:=xlPicture
               
                Set xRg = .Parent.Offset(0, 1)
                xRg.PasteSpecial  

                Selection.ShapeRange.LockAspectRatio = msoTrue
                Selection.Height = xRg.Height
                .Visible = visBool
                .Text Text:=cmtTxt
                .Shape.Fill.Solid
                .Shape.TextFrame.AutoSize = True
               
                i = i + 1
                Debug.Print i; rngZelle.Address
               
            End With
         End If
    End With
   
LabelA:

Application.CutCopyMode = False
   
Next rngZelle
   
    Application.CutCopyMode = False
    Application.Calculation = xlCalculationAutomatic
    Application.ScreenUpdating = True

End Sub
Antworten Top
#2
Wo ist der Unterschied von @office  und @homeoffice?  

Liegen die Dateien jeweils lokal auf dem Rechner oder geht das über eine Netzwerkresource?

Sind die Dateien evtl. in der geschützten Ansicht geöffnet?

Existiert ein Blattschutz oder dergleichen?
[-] Folgende(r) 1 Nutzer sagt Danke an ralf_b für diesen Beitrag:
  • TxbyFmjy
Antworten Top
#3
https://www.herber.de/forum/messages/1840555.html
[-] Folgende(r) 1 Nutzer sagt Danke an Werner.M für diesen Beitrag:
  • TxbyFmjy
Antworten Top
#4
Jetzt funktioniert es fehlerfrei, wenn
  • der Makrostart bei geöffnetem Modul nicht über die Menüleiste "Ausführen" --> "Sub/UserForm ausführen" des Entwicklertools Microsoft Visual Basic for Application, sondern bei geöffnetem Modul mittels der Taste F5 ausgelöst wird oder
  • der Makrostart über Reiter Ansicht --> Button Makros --> Makros anzeigen --> {Makroname auswählen} ausgelöst wird.
Code:
Sub insert_userpicture_in_comments_final()
'** Dimensionierung der Variablen
Dim rngZelle As Range
Dim strFilename As Variant
Dim strFilter As String
Dim ScaleValue As Single
Dim ScaleValue2 As Single
Dim objPic As IPictureDisp
Dim Source As String
Dim i As Integer

If ActiveSheet.Comments.Count = 0 Then
MsgBox "No comments in entire sheet"
Exit Sub
End If

'Dateiauswahl filtern
strFilter = "JPG Files (*.jpg), *.jpg" _
& ", GIF Files (*.gif), *.gif" _
& ", Bitmaps (*.bmp), *.bmp" _
& ", WMF Files (*.wmf), *.wmf"

' Dialogfenster zur Auswahl eines Bildes öffnen
strFilename = Application.GetOpenFilename(strFilter)

' Wenn kein Bild ausgewählt wurde, Prozedur beenden
If strFilename = False Then GoTo LabelA

Source = (CStr(strFilename))

' Set objPic = LoadPicture(Bild)
Set objPic = LoadPicture(Source)

DoEvents

With objPic
ScaleValue = .Width / .Height
End With

If MsgBox(ScaleValue, vbOKCancel) = vbCancel Then GoTo LabelA

Application.CutCopyMode = False
DoEvents

Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual

'** Alle markierten rngZellen durchlaufen
For Each rngZelle In Selection.Cells
With rngZelle
If Not .Comment Is Nothing Then

'Insert The Image and Resize
With .Comment.Shape

.Shadow.Visible = msoFalse

.LockAspectRatio = msoFalse
.Width = 150
' .Width = ScaleValue * .Height
.Height = .Width / ScaleValue
.Fill.UserPicture strFilename

DoEvents

.LockAspectRatio = msoTrue

ScaleValue2 = .Width / .Height

i = i + 1
Debug.Print i; rngZelle.Address; ScaleValue; ScaleValue2

End With
End If
End With

Application.CutCopyMode = False
DoEvents

Next rngZelle

LabelA:

Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True

Application.CutCopyMode = False
DoEvents

Code:
Sub extract_userpicture_from_comments_final()
'** Dimensionierung der Variablen
Dim rngZelle As Range
Dim xRg As Range
Dim visBool As Boolean
Dim cmtTxt As String
Dim i As Integer

If ActiveSheet.Comments.Count = 0 Then
MsgBox "No comments in entire sheet"
Exit Sub
End If

Application.CutCopyMode = False
DoEvents

Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual

'** Alle markierten rngZellen durchlaufen
For Each rngZelle In Selection.Cells
With rngZelle

rngZelle.Select

If .Comment Is Nothing Then
GoTo LabelA
Else

'Extract The Image
With .Comment

cmtTxt = .Text
.Text Text:="" & Chr(10) & ""
visBool = .Visible
.Visible = True
.Shape.CopyPicture _
Appearance:=xlScreen, Format:=xlPicture

DoEvents

Set xRg = .Parent.Offset(0, 20)

xRg.Select

' xRg.PasteSpecial

ActiveSheet.PasteSpecial

DoEvents

Selection.ShapeRange.LockAspectRatio = msoTrue
' Selection.Width = xRg.Width
Selection.Height = xRg.Height
.Visible = visBool
.Text Text:=cmtTxt
.Shape.Fill.Solid
DoEvents

.Shape.TextFrame.AutoSize = True

i = i + 1
Debug.Print i; rngZelle.Address

End With
End If
End With

LabelA:

Application.CutCopyMode = False
DoEvents

Next rngZelle

Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True

Application.CutCopyMode = False
DoEvents

End Sub


Angehängte Dateien
.bmp   Erdbeere-8.bmp (Größe: 95,12 KB / Downloads: 2)
.bmp   Orange-25.bmp (Größe: 85,37 KB / Downloads: 1)
.xlsm   PasteSpecial-final.xlsm (Größe: 94,29 KB / Downloads: 1)
Antworten Top
#5
(24.07.2021, 11:47)ralf_b schrieb: Wo ist der Unterschied von @office  und @homeoffice?  

Liegen die Dateien jeweils lokal auf dem Rechner oder geht das über eine Netzwerkresource?

Sind die Dateien evtl. in der geschützten Ansicht geöffnet?

Existiert ein Blattschutz oder dergleichen?

Speicherort: lokal
geschützte Ansicht: nein
Blattschutz oder dergleichen: nein

Wegen der Laufzeitfehler @office habe ich folgende Änderung vorgenommen: Wird das Bild nicht in die Zelle eingefügt, dann wird zwar der Fehler ignoriert, aber das Einfügen des Bildes solange wiederholt bis es geklappt hat.

Code:
On Error Resume Next

Code:
LabelB:
i = i + 1
If Err = 1004 Then j = j + 1
Debug.Print i; rngZelle.Address; rngZelle.Comment.Parent.Offset(0, 20).Address; Err; j
           
On Error GoTo 0
On Error Resume Next

Code:
If Err = 1004 Then GoTo LabelB

Und komplett:

Code:
Sub extract_userpicture_from_comments_final_2()
'** Dimensionierung der Variablen
Dim rngZelle As Range
Dim xRg As Range
Dim visBool As Boolean
Dim cmtTxt As String
Dim i As Integer
Dim j As Integer
   
i = 0
j = 0

If ActiveSheet.Comments.Count = 0 Then
MsgBox "No comments in entire sheet"
Exit Sub
End If

Application.CutCopyMode = False
DoEvents

Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual

'** Alle markierten rngZellen durchlaufen
For Each rngZelle In Selection.Cells
With rngZelle

rngZelle.Select

If .Comment Is Nothing Then
GoTo LabelA
Else

'Extract The Image
With .Comment

On Error Resume Next

cmtTxt = .Text
.Text Text:="" & Chr(10) & ""
visBool = .Visible
.Visible = True
.Shape.CopyPicture _
Appearance:=xlScreen, Format:=xlPicture

DoEvents

Set xRg = .Parent.Offset(0, 20)

xRg.Select
     
LabelB:
i = i + 1
If Err = 1004 Then j = j + 1
Debug.Print i; rngZelle.Address; rngZelle.Comment.Parent.Offset(0, 20).Address; Err; j
           
On Error GoTo 0
On Error Resume Next

' xRg.PasteSpecial

ActiveSheet.PasteSpecial Format:="Bild (Erweiterte Metadatei)", Link:=False, DisplayAsIcon:=False

DoEvents

If Err = 1004 Then GoTo LabelB

Selection.ShapeRange.LockAspectRatio = msoTrue
' Selection.Width = xRg.Width
Selection.Height = xRg.Height
.Visible = visBool
.Text Text:=cmtTxt
.Shape.Fill.Solid
DoEvents

.Shape.TextFrame.AutoSize = True

End With
End If
End With

LabelA:

Application.CutCopyMode = False
DoEvents

Next rngZelle

Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True

Application.CutCopyMode = False
DoEvents

End Sub

Code:
Sub insert_userpicture_in_comments_final()
'** Dimensionierung der Variablen
Dim rngZelle As Range
Dim strFilename As Variant
Dim strFilter As String
Dim ScaleValue As Single
Dim ScaleValue2 As Single
Dim objPic As IPictureDisp
Dim Source As String
Dim i As Integer

If ActiveSheet.Comments.Count = 0 Then
MsgBox "No comments in entire sheet"
Exit Sub
End If

'Dateiauswahl filtern
strFilter = "JPG Files (*.jpg), *.jpg" _
& ", GIF Files (*.gif), *.gif" _
& ", Bitmaps (*.bmp), *.bmp" _
& ", WMF Files (*.wmf), *.wmf"

' Dialogfenster zur Auswahl eines Bildes öffnen
strFilename = Application.GetOpenFilename(strFilter)

' Wenn kein Bild ausgewählt wurde, Prozedur beenden
If strFilename = False Then GoTo LabelA

Source = (CStr(strFilename))

' Set objPic = LoadPicture(Bild)
Set objPic = LoadPicture(Source)

DoEvents

With objPic
ScaleValue = .Width / .Height
End With

If MsgBox(ScaleValue, vbOKCancel) = vbCancel Then GoTo LabelA

Application.CutCopyMode = False
DoEvents

Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual

'** Alle markierten rngZellen durchlaufen
For Each rngZelle In Selection.Cells
With rngZelle
If Not .Comment Is Nothing Then

'Insert The Image and Resize
With .Comment.Shape

.Shadow.Visible = msoFalse

.LockAspectRatio = msoFalse
.Width = 150
' .Width = ScaleValue * .Height
.Height = .Width / ScaleValue
.Fill.UserPicture strFilename

DoEvents

.LockAspectRatio = msoTrue

ScaleValue2 = .Width / .Height

i = i + 1
Debug.Print i; rngZelle.Address; ScaleValue; ScaleValue2

End With
End If
End With

Application.CutCopyMode = False
DoEvents

Next rngZelle

LabelA:

Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True

Application.CutCopyMode = False
DoEvents
   
End Sub


Angehängte Dateien
.bmp   Erdbeere-8.bmp (Größe: 95,12 KB / Downloads: 1)
.bmp   Orange-25.bmp (Größe: 85,37 KB / Downloads: 2)
.xlsm   PasteSpecial-final_2.xlsm (Größe: 94,59 KB / Downloads: 1)
Antworten Top
#6
da bei mir kein Fehler auftritt, kann ich nicht helfen.
[-] Folgende(r) 1 Nutzer sagt Danke an ralf_b für diesen Beitrag:
  • TxbyFmjy
Antworten Top
#7
(24.07.2021, 07:11)TxbyFmjy schrieb: Hallo,

Code:
Laufzeitfehler '1004': Die PasteSpecial-Methode des Range-Objektes konnte nicht ausgeführt werden.

Code:
Laufzeitfehler '1004': Microsoft Excel kann die Daten nicht einfügen.

Diese Fehler werden mutmaßlich dadurch verursacht, dass der Zugriff auf das Clipboard durch ein anderes Programm gestört wird.

Unter Microsoft Excel cannot paste the data wurde über dieses Phänomen diskutiert:

Zitat:Verbundene Zellen:
Does your data have merged cells? It could be one of the possibilities. It may not be possible to paste data from a merged cell range into a non-merged cells range. Select the data, click on Merge and Center to toggle it off and try the copy the data again.

Zitat:Skype with its click to call functions
Hello everybody!

I got this problem today... besides, all MS Office 365 programs failed to provide paste options.

After reinstalling the Office 365, uninstalling Skype with its click to call functions (in vain) i discovered that clipboard and copy & paste functions were stolen by Pushbullet software. After disabling "Universal copy & paste" function in settings of Pushbullet,  copy and paste functions recovered in Excel and other MS Office suite applications.

Hope this experience works with you. You may have other software (or add-on) that monitors clipboard and overrides MS Office functionality.

Zitat:Clipboard
Simply shutting down my clipboard manager for the time I use Excel has 100% eliminated this error.

Zitat:Bedngte Formatierung
This worked for me

In Excel 2007/2010/2013:
1. On the Home Ribbon > Conditional Formatting
2. Clear rules from entire worksheet or cells
3. Follow above steps for each worksheet in the file

Mit folgender Verbesserung sind nun auch die Run-time error '1004' verschwunden:

Code:
Option Explicit
Declare Sub Sleep Lib "kernel32" (ByVal dwmilliseconds As Long)

Code:
Sleep (50)

Und komplett:

Code:
Option Explicit
Declare Sub Sleep Lib "kernel32" (ByVal dwmilliseconds As Long)
Sub extract_userpicture_from_comments_final_3()
'** Dimensionierung der Variablen
Dim rngZelle As Range
Dim xRg As Range
Dim visBool As Boolean
Dim cmtTxt As String
Dim i As Integer
Dim j As Integer
  
i = 0
j = 0

If ActiveSheet.Comments.Count = 0 Then
MsgBox "No comments in entire sheet"
Exit Sub
End If

Application.CutCopyMode = False
DoEvents

Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual

'** Alle markierten rngZellen durchlaufen
For Each rngZelle In Selection.Cells
With rngZelle

rngZelle.Select

If .Comment Is Nothing Then
GoTo LabelA
Else

'Extract The Image
With .Comment

On Error Resume Next

cmtTxt = .Text
.Text Text:="" & Chr(10) & ""
visBool = .Visible
.Visible = True
.Shape.CopyPicture _
Appearance:=xlScreen, Format:=xlPicture

DoEvents

Sleep (50)

Set xRg = .Parent.Offset(0, 20)

xRg.Select
    
LabelB:
i = i + 1
If Err = 1004 Then j = j + 1
Debug.Print i; rngZelle.Address; rngZelle.Comment.Parent.Offset(0, 20).Address; Err; j
          
On Error GoTo 0
On Error Resume Next

' xRg.PasteSpecial

ActiveSheet.PasteSpecial Format:="Bild (Erweiterte Metadatei)", Link:=False, DisplayAsIcon:=False

DoEvents

If Err = 1004 Then GoTo LabelB

Selection.ShapeRange.LockAspectRatio = msoTrue
' Selection.Width = xRg.Width
Selection.Height = xRg.Height
.Visible = visBool
.Text Text:=cmtTxt
.Shape.Fill.Solid
DoEvents

.Shape.TextFrame.AutoSize = True

End With
End If
End With

LabelA:

Application.CutCopyMode = False
DoEvents

Next rngZelle

Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True

Application.CutCopyMode = False
DoEvents

End Sub

Code:
Sub insert_userpicture_in_comments_final()
'** Dimensionierung der Variablen
Dim rngZelle As Range
Dim strFilename As Variant
Dim strFilter As String
Dim ScaleValue As Single
Dim ScaleValue2 As Single
Dim objPic As IPictureDisp
Dim Source As String
Dim i As Integer

If ActiveSheet.Comments.Count = 0 Then
MsgBox "No comments in entire sheet"
Exit Sub
End If

'Dateiauswahl filtern
strFilter = "JPG Files (*.jpg), *.jpg" _
& ", GIF Files (*.gif), *.gif" _
& ", Bitmaps (*.bmp), *.bmp" _
& ", WMF Files (*.wmf), *.wmf"

' Dialogfenster zur Auswahl eines Bildes öffnen
strFilename = Application.GetOpenFilename(strFilter)

' Wenn kein Bild ausgewählt wurde, Prozedur beenden
If strFilename = False Then GoTo LabelA

Source = (CStr(strFilename))

' Set objPic = LoadPicture(Bild)
Set objPic = LoadPicture(Source)

DoEvents

With objPic
ScaleValue = .Width / .Height
End With

If MsgBox(ScaleValue, vbOKCancel) = vbCancel Then GoTo LabelA

Application.CutCopyMode = False
DoEvents

Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual

'** Alle markierten rngZellen durchlaufen
For Each rngZelle In Selection.Cells
With rngZelle
If Not .Comment Is Nothing Then

'Insert The Image and Resize
With .Comment.Shape

.Shadow.Visible = msoFalse

.LockAspectRatio = msoFalse
.Width = 150
' .Width = ScaleValue * .Height
.Height = .Width / ScaleValue
.Fill.UserPicture strFilename

DoEvents

.LockAspectRatio = msoTrue

ScaleValue2 = .Width / .Height

i = i + 1
Debug.Print i; rngZelle.Address; ScaleValue; ScaleValue2

End With
End If
End With

Application.CutCopyMode = False
DoEvents

Next rngZelle

LabelA:

Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True

Application.CutCopyMode = False
DoEvents
  
End Sub


Angehängte Dateien
.bmp   Erdbeere-8.bmp (Größe: 95,12 KB / Downloads: 1)
.bmp   Orange-25.bmp (Größe: 85,37 KB / Downloads: 1)
.xlsm   PasteSpecial-final_3.xlsm (Größe: 94,83 KB / Downloads: 1)
Antworten Top


Gehe zu:


Benutzer, die gerade dieses Thema anschauen: 1 Gast/Gäste