Public Declare PtrSafe Function Empt圜lipboard Lib "user32" () As Long Public Declare PtrSafe Function OpenClipboard Lib "user32" (ByVal hwnd As Long) As Long In a module, I had the following code: Option Explicit I chose to try 5 times with a 1-second pause between each try. Since we are looping until the clipboard has data, we need to provide a mechanism to prevent an infinite loop. For the first question, based upon this answer amongst others, you could do something like this: Option ExplicitĪpplication.Wait Now + TimeValue("00:00:01") The questions that need answers are "How do I wait until the clipboard has data?" and "How do I know when pasting is complete". It is possible to solve my problem with the according use of the error handler. Preferably I want to work with the error handler and not with the timer as it is unreliable and depending on CPU usage.Ĭan someone tell me why the code with the error handler does not work and is sometimes pasting the same shape 2 times?Īpparently my understanding of how the error handler works was insufficient. So I added a timer after the pasting Public Sub Warten(ByVal MilliSekunden As Double)īut this is unreliable because sometimes 100ms are sufficient, but sometimes even 2000ms aren't sufficient and I want the macro to run on most (also older) machines. "PasteExcelTableSourceFormatting"īut then sometimes there's an issue with the assigning of the name for the shape, because it does not paste fast enough. It seems that the error handler does not exactly what I think it does because sometimes it just pastes the same shape 2 times when running this code. Therefore I tried this to just repeat the copying and pasting process if an error happens: ALLGCOPY: Clipboard is empty or conains data which may not be pasted hereīecause (I think) the clipboard is not populated in time. The following runtime error happens from time to time: MyPresentation.Slides(2).Shapes(3).Name = "AllgShape"Īnd it works most of the time, but not always. I am trying to copy a range of cells from Excel and paste it onto a slide of a PowerPoint presentation (both version 2016) with the original formatting.
0 Comments
Leave a Reply. |