PDA

View Full Version : [SOLVED] Error 1004 with method "Columns" - only when opening the file



nikki333
06-05-2018, 01:18 PM
Hi Folks

Recently, I'm encountering a runtime error 1004 saying sth. in German like that "the method 'columns' for the object '_Global' has failed"

This happens right after opening the file and accepting the "edit document" macro security popup (attachment 1).

The failing line of code is highlighted in attachment 2 (hope it's visible enough).

The strange thing is, that the code seems legit and totally works (if I end debugging and run the sub again), except when I open the document. Any ideas?

BTW, the 2 variables involved are declared as global in another module, could that be an issue?

Cheers



22369 22370

SamT
06-05-2018, 07:29 PM
Sounds like a timing issue; Try putting a dot in front of "Columns"

If that doesn't help, try
Dim CC as Long

'After the With [Worksheet] line, place
CC = .Columns.Count 'Note DOTsThen replace "Columns.Count" in the problem line with "CC"

p45cal
06-06-2018, 04:21 AM
try just putting a dot in front of Columns - it might just work!