Excel Macro fails 'Subscript out of Range' but works in Debug mode!


Posted by Brian on July 19, 2001 11:39 AM

Hi,

I have a macro that when run opens a .txt file and copies it to another page. It does a whole lot more but for simplicity sake here's the problem. when I run the macro I get an error:

Error
Routine: ACR- ActivateVB
File: ACR.TXT
Error: -2147352565 Subscript out of Range

When I go to Debug mode and try to step through the code everyhting works fine. Here is the VB code where the error message is ACR- ActivateVB:


ErrorMsg = "ACR - Activate VB"
SendKeys "%{F11}", True
AppActivate "Microsoft Visual Basic"
' Set object to the module you want to export.
Set modObj = Application.VBE.ActiveVBProject.VBComponents.Item("SelectACRView")
SendKeys "%FC", True


AppActivate "Microsoft Excel"
' Place code in a string.
strCode = modObj.CodeModule.Lines(1, modObj.CodeModule.CountOfLines)

The module: "SelectACRView" exists in the Macro.

Anyone have any ideas?

Thanks,

Brian



Posted by Brian on July 21, 2001 5:39 PM

Can anyone help?

AppActivate "Microsoft Excel"