I am newly encountering this error. I am not sure where it is coming form. I have run this bit of code literally thousands of times and now today for some stupid reason it is failing. I have been looking at this code and I it has not changed in months in addition to this still is the identical code that the VBA Recording tool generates. This is the Error message:
and this is the bit of code that my program is getting stuck on:
Sheets("Sheet1").Select
Cells(wHeaders, 1).Select
Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
Selection.Copy
Workbooks(CurrWB).Activate
Sheets(CurrSheet).Select
Sheets(CurrSheet).Activate
Cells(CurrRow, CurrCol).Select
ActiveSheet.PasteSpecial Format:="HTML", Link:=False, DisplayAsIcon:= _
False, NoHTMLFormatting:=True 'THIS IS THE LINE WITH THE ERROR
ActiveSheet.Paste
Selection.EntireColumn.AutoFit
Because there have been no changes and that the code builder is still creating this same line I am very confused. Help would be amazing. Also because I know that you are all going to ask, yes my variables are defined.
Dim CurrSheet As Variant
Dim CurrWB As Variant
Dim CurrCol As Variant
Dim CurrRow As Variant
There is one last one and that is passed in the Sub and that is Sub CoolProg(Optional wHeaders As Integer = 1)
UPDATE: I am not sure why this is the case but the error seems to go away when I make the following edit to the line where the debugger goes.
Worksheets(CurrSheet).PasteSpecial Format:="HTML", Link:=False, DisplayAsIcon:= _
False ', NoHTMLFormatting:=True
All that I did was comment out the NoHTMLFormatting section, can someone help me understand why this works and maybe what is the underlying cause of this error. I want to make sure that I understand this so that I can fix what code I need to.
Update #2 .... So this error only happens when I have a Google Chrome window open and I am running this code. I closed Chrome and it worked. There was a similar task that relied on this but I know to be VERY Compute heavy and it uses this sub within it and I couldn't get through it. I checked task manager and saw that chrome was at the top (PS it SUCKS resources) so I killed and and now it works. If someone can explain what is going on that would be amazing.
Update#3
I added a 2 second pause before the problematic line runs and it seems to solve the issue. I am not sure why this works but it seems that there is a larger resource draw and my machines needs the time for some of the resources to free up so that it will work. If someone has some insight as to why this is a solution that works that would be great. The code now looks like:
Cells(CurrRow, CurrCol).Select
Application.Wait (Now + TimeValue("0:00:02")) 'Added this line for the delay
ActiveSheet.PasteSpecial Format:="HTML", Link:=False, DisplayAsIcon:= _
False, NoHTMLFormatting:=True 'this is the problem code