I am trying to copy from an external file and paste into the currently open file.
The code I'm using is below. Sometimes it works and sometimes it doesn't.
I'm still quite new to VBA and really not sure what the issue was... but I was suspecting the multiple connections to the same file. I first connect when I'm asking the user to select what sheet to use. I then connect again for each column to copy and paste. I tried setting up global variables for the worksheet and workbook variables so that I only had to SET them once. That seemed to work for a while and now the error is back.
You'll see that I am not doing a direct copy - paste (in one line). This always failed. I came up with a solution that was to Copy first, then select the active sheet and then the cell and finally just do an activesheet.paste. This was working but is now where the program fails intermittently with the error "Copy method of range class failed".
Other observations:
1. I can't get rid of the clipboard warning when the script ends despite using "Application.DisplayAlerts = False" as well as "Application.CutCopyMode = False" in several placees.
2. Sometimes when I go to the debug window, I can just click the "play" button and then the code finishes properly. Other times, it stays stuck on that activesheet.paste line.
3. When the code fails, I think there is a hanging open connection to the external WS. I figure this by seeing that when I close and open Excel, I get that external WS opening before the file I've selected. In this state, issue seems to happen more often.
Let me know if I can provide any other helpful information.
Thanks!
Bookmarks