VBA Refresh Connections : Error 1004 Application-defined or object-defined error

%3CLINGO-SUB%20id%3D%22lingo-sub-215287%22%20slang%3D%22en-US%22%3EVBA%20Refresh%20Connections%20%3A%20Error%201004%20Application-defined%20or%20object-defined%20error%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-215287%22%20slang%3D%22en-US%22%3E%3CP%3EI%20have%20a%20report%20using%20Power%20Query%20and%20Power%20Pivot%2C%20that%20is%20refreshed%20using%20VBA.%20It%20worked%20well%20for%20several%20years%20%2Cand%20since%20last%20week%20the%20VBA%20stops%20in%20Debug%20mode%20on%20the%20Refresh%20method%20of%20the%20connection%2C%20with%20the%20above%201004%20error.%20No%20reasons%20for%20that%2C%20especially%20as%20i%20can%20hit%20F8%20and%20the%20line%20will%20execute%20perfectly%20manually.%20For%20some%20reason%2C%20VBA%20is%20not%20running%20properly%20since%20one%20week.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESometimes%20i%20have%20an%20error%20message%20mentoinning%20a%20file%20in%20my%20TEMP%20folder.%3C%2FP%3E%3CP%3E%3CBR%20%2F%3EAny%20idea%20why%20%3F%20how%20can%20i%20find%20which%20program%20is%20interferring%20%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-215287%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EMacros%20%26amp%3B%20VBA%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ENeed%20Help%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-216313%22%20slang%3D%22en-US%22%3ERe%3A%20RE%3A%20VBA%20Refresh%20Connections%20%3A%20Error%201004%20Application-defined%20or%20object-defined%20error%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-216313%22%20slang%3D%22en-US%22%3EHi%20Jean%2C%3CBR%20%2F%3E%3CBR%20%2F%3EGlad%20you%20got%20this%20sorted!%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-216290%22%20slang%3D%22en-US%22%3ERe%3A%20RE%3A%20VBA%20Refresh%20Connections%20%3A%20Error%201004%20Application-defined%20or%20object-defined%20error%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-216290%22%20slang%3D%22en-US%22%3E%3CP%3ESo%20first%20i%20believe%20the%20root%20cause%20was%20actually%20different%2C%20and%20the%20issue%20i%20reported%20here%20is%20just%20a%20secondary%20effect.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EEssentialy%2C%20the%20problem%20seemed%20to%20come%20from%20Micro%20Trends%20anti%20virus%20who%20was%20conflicting%20with%20my%20report.%20I%20already%20read%20similar%20cases.%26nbsp%3BI%20asked%20my%20IT%20to%20%22fix%22%20that%20and%20now%20it%20seems%20none%20of%20the%20error%20messages%20show%20up%20anymore%2C%20neither%20those%20mentionning%20a%20vertipaq.xml%20file%20in%20Temp%2C%20nor%20the%20VBA%20refresh%20issues.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-215373%22%20slang%3D%22en-US%22%3ERe%3A%20RE%3A%20VBA%20Refresh%20Connections%20%3A%20Error%201004%20Application-defined%20or%20object-defined%20error%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-215373%22%20slang%3D%22en-US%22%3E%3CP%3EAre%20there%20multiple%20refreshes%20in%20the%20code%3F%20I%20see%20you%20have%20not%20set%20it%20to%20refresh%20synchonously%2C%20so%20a%20connection%20might%20be%20requested%20to%20refresh%20while%20a%20previous%20one%20has%20not%20yet%20finished.%3C%2FP%3E%0A%3CPRE%3EActiveWorkbook.Connections(%22MYCALL21%22).Refresh%20False%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-215303%22%20slang%3D%22en-US%22%3ERe%3A%20RE%3A%20VBA%20Refresh%20Connections%20%3A%20Error%201004%20Application-defined%20or%20object-defined%20error%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-215303%22%20slang%3D%22en-US%22%3EDeleting%20all%20the%20files%20in%20the%20Temp%20folder%20doesnt%20seem%20to%20fix%20the%20issue.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-215299%22%20slang%3D%22en-US%22%3ERE%3A%20VBA%20Refresh%20Connections%20%3A%20Error%201004%20Application-defined%20or%20object-defined%20error%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-215299%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20JKP%20!%20I'm%20honored%20to%20have%20you%20read%20my%20post%2C%20i've%20used%20your%20precious%20help%20a%20lot%20in%20the%20past.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIn%20reality%2C%20I'm%20pretty%20sure%20the%20code%20is%20not%20really%20the%20problem%2C%20since%20it%20worked%20for%206-7%20years%20with%20no%20issues.%20And%20again%2C%20it%20just%20stops%20on%20the%20line%20of%20code%2C%20and%20if%20i%20hit%20F8%20it%20continues%20with%20no%20issue.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20believe%20the%20problem%20is%20inherent%20to%20Windows%2C%20or%20a%20conflicting%20app%2C%20or%20update.%20Moreover%2C%20some%20users%20dont%20run%20into%20the%20error%20message%2C%20while%20others%20do.%20Still%2C%20here%20the%20code%20(that%20includes%20SQL%20statements%2C%20confidential%20so%20I%20have%20to%20hide%20the%20details).%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESometimes%20also%2C%20Excel%20just%20freezes%20('Not%20Responding')%20and%20doesnt%20finish%20the%20code.%3C%2FP%3E%3CP%3ESometimes%20also%2C%20Excel%20closes%20completely%20without%20any%20warning.%3C%2FP%3E%3CP%3EAnd%20also%2C%20sometimes%20there%20is%20an%20error%20message%20mentionning%20the%20Temp%20folder%2C%20as%20such%20%3A%20%22%3C%2FP%3E%3CP%3E%3CSTRONG%3EWe%20couldn't%20refresh%20multiple%20table%20including%20%E2%80%A6%20the%20following%20error%20occurred%20while%20opening%20the%20file%20%E2%80%A6%20xxx.162.cub.xml%26nbsp%3B%20%E2%80%A6%20the%20requested%20operation%20cannot%20be%20performed%20on%20a%20file%20with%20a%20user-mapped%20section%20open.%22%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20code%20as%20it%20stops%20on%20the%20last%20line%20(Refresh)%3A%3C%2FP%3E%3CP%3EWith%20ActiveWorkbook.Connections(%22MYCALL21%22).OLEDBConnection%20(...)%20With%20ActiveWorkbook.Connections(%22MYCALL21%22)%20.Name%20%3D%20%22MYCALL21%22%20.Description%20%3D%20%22%22%20End%20With%20%3CSTRONG%3EActiveWorkbook.Connections(%22MYCALL21%22).Refresh%3C%2FSTRONG%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-215294%22%20slang%3D%22en-US%22%3ERe%3A%20VBA%20Refresh%20Connections%20%3A%20Error%201004%20Application-defined%20or%20object-defined%20error%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-215294%22%20slang%3D%22en-US%22%3EIf%20you%20want%20us%20to%20help%2C%20show%20the%20code.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1935718%22%20slang%3D%22en-US%22%3ERe%3A%20VBA%20Refresh%20Connections%20%3A%20Error%201004%20Application-defined%20or%20object-defined%20error%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1935718%22%20slang%3D%22en-US%22%3ESheets(%22CONSOLIDAT%22).Cells.ClearContents%3CBR%20%2F%3Ecol%20%3D%20Application.WorksheetFunction.CountA(Range(%22A3%22%2C%20Range(%22A3%22).End(xlToRight)))%3CBR%20%2F%3ERow%20%3D%20Application.WorksheetFunction.CountA(Range(%22A3%22%2C%20Range(%22A3%22).End(xlDown)))%3CBR%20%2F%3ESheets(%22BOA%22).Activate%3CBR%20%2F%3ESheets(%22BOA%22).Range(%22b2%3AH2%22).Copy%3CBR%20%2F%3ESheets(%22CONSOLIDAT%22).Range(%22A1%3AE1%22).PasteSpecial%20xlPasteValues%3CBR%20%2F%3ESheets(%22BOA%22).Select%3CBR%20%2F%3ESheets(%22BOA%22).Range(%22b3%22).Select%3CBR%20%2F%3ESheets(%22BOA%22).Range(%22b3%22%2C%20Cells(Row%2C%20col)).Select%3CBR%20%2F%3E%3C%2FLINGO-BODY%3E
New Contributor

I have a report using Power Query and Power Pivot, that is refreshed using VBA. It worked well for several years ,and since last week the VBA stops in Debug mode on the Refresh method of the connection, with the above 1004 error. No reasons for that, especially as i can hit F8 and the line will execute perfectly manually. For some reason, VBA is not running properly since one week.

 

Sometimes i have an error message mentoinning a file in my TEMP folder.


Any idea why ? how can i find which program is interferring ?

 

7 Replies
If you want us to help, show the code.

Hi JKP ! I'm honored to have you read my post, i've used your precious help a lot in the past.

 

In reality, I'm pretty sure the code is not really the problem, since it worked for 6-7 years with no issues. And again, it just stops on the line of code, and if i hit F8 it continues with no issue.

 

I believe the problem is inherent to Windows, or a conflicting app, or update. Moreover, some users dont run into the error message, while others do. Still, here the code (that includes SQL statements, confidential so I have to hide the details).

 

Sometimes also, Excel just freezes ('Not Responding') and doesnt finish the code.

Sometimes also, Excel closes completely without any warning.

And also, sometimes there is an error message mentionning the Temp folder, as such : "

We couldn't refresh multiple table including … the following error occurred while opening the file … xxx.162.cub.xml  … the requested operation cannot be performed on a file with a user-mapped section open."

 

The code as it stops on the last line (Refresh):

With ActiveWorkbook.Connections("MYCALL21").OLEDBConnection (...) With ActiveWorkbook.Connections("MYCALL21") .Name = "MYCALL21" .Description = "" End With ActiveWorkbook.Connections("MYCALL21").Refresh

Deleting all the files in the Temp folder doesnt seem to fix the issue.

Are there multiple refreshes in the code? I see you have not set it to refresh synchonously, so a connection might be requested to refresh while a previous one has not yet finished.

ActiveWorkbook.Connections("MYCALL21").Refresh False

 

 

So first i believe the root cause was actually different, and the issue i reported here is just a secondary effect.

 

Essentialy, the problem seemed to come from Micro Trends anti virus who was conflicting with my report. I already read similar cases. I asked my IT to "fix" that and now it seems none of the error messages show up anymore, neither those mentionning a vertipaq.xml file in Temp, nor the VBA refresh issues.

Sheets("CONSOLIDAT").Cells.ClearContents
col = Application.WorksheetFunction.CountA(Range("A3", Range("A3").End(xlToRight)))
Row = Application.WorksheetFunction.CountA(Range("A3", Range("A3").End(xlDown)))
Sheets("BOA").Activate
Sheets("BOA").Range("b2:H2").Copy
Sheets("CONSOLIDAT").Range("A1:E1").PasteSpecial xlPasteValues
Sheets("BOA").Select
Sheets("BOA").Range("b3").Select
Sheets("BOA").Range("b3", Cells(Row, col)).Select