ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Automation Error (https://www.excelbanter.com/excel-programming/341493-automation-error.html)

al

Automation Error
 
Hello
My code:
Application.ScreenUpdating = False

Sheets("Sheet1").Select
ActiveSheet.Range("D2:s28").Select
Selection.Copy
Windows("AnotherOpenFile.xls").Activate
Sheets("Sheet2").Select
ActiveSheet.Range("G1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Sheets("Sheet3").Select
'
Workbooks.OpenText Filename:="C:\MyPath\Myfile1.boo", Origin _
:=437, StartRow:=1, DataType:=xlFixedWidth,
FieldInfo:=Array(Array(0, 1), _
Array(2, 1), Array(5, 1), Array(8, 1), Array(12, 1), Array(16, 1),
Array(20, 1), Array(24, 1 _
), Array(28, 1), Array(32, 1), Array(36, 1), Array(40, 1), Array(44,
1), Array(48, 1), Array _
(52, 1), Array(56, 1), Array(60, 1), Array(64, 1), Array(68, 1),
Array(72, 1), Array(76, 1), _
Array(80, 1), Array(84, 1), Array(88, 1), Array(92, 1), Array(96,
1), Array(100, 1)), _
TrailingMinusNumbers:=True
ActiveWindow.Close
Workbooks.OpenText Filename:="C:\MyPath\Myfile2.boo", Origin _
:=437, StartRow:=1, DataType:=xlFixedWidth,
FieldInfo:=Array(Array(0, 1), _
Array(2, 1), Array(5, 1), Array(8, 1), Array(12, 1), Array(16, 1),
Array(20, 1), Array(24, 1 _
), Array(28, 1), Array(32, 1), Array(36, 1), Array(40, 1), Array(44,
1), Array(48, 1), Array _
(52, 1), Array(56, 1), Array(60, 1), Array(64, 1), Array(68, 1),
Array(72, 1), Array(76, 1), _
Array(80, 1), Array(84, 1), Array(88, 1), Array(92, 1), Array(96,
1), Array(100, 1)), _
TrailingMinusNumbers:=True
ActiveWindow.Close
Workbooks.OpenText Filename:="C:\MyPath\Myfile3.boo", Origin _
:=437, StartRow:=1, DataType:=xlFixedWidth,
FieldInfo:=Array(Array(0, 1), _
Array(2, 1), Array(5, 1), Array(8, 1), Array(12, 1), Array(16, 1),
Array(20, 1), Array(24, 1 _
), Array(28, 1), Array(32, 1), Array(36, 1), Array(40, 1), Array(44,
1), Array(48, 1), Array _
(52, 1), Array(56, 1), Array(60, 1), Array(64, 1), Array(68, 1),
Array(72, 1), Array(76, 1), _
Array(80, 1), Array(84, 1), Array(88, 1), Array(92, 1), Array(96,
1), Array(100, 1)), _
TrailingMinusNumbers:=True
ActiveWindow.Close
'Application.ScreenUpdating = True
End Sub

The 3 files myfile1 myfile2 and myfile3 are all text files. I have to open
them in order to get the values updated on anotheropenfile.xls. This part
was added as well as application.screenupdating true/false. The macro ran
fine before but now I get an error: "Automation Error Exception Occurred" and
Excel shuts down. I can take out screenupdating true/false and it works some
better but still shuts down occasionally. Reading the NG it seems as though
that adding DoEvents may help, but I am unsure as how to do this. Can some
one please advise?
Thanks!

Simon Murphy

Automation Error
 
Stick a doEvents before and after each open
It just gives windows chance to catch up with other requests from other
applications
eg
doEvents
workbooks.open....
doEvents

cheers
Simon

"Al" wrote in message
...
Hello
My code:
Application.ScreenUpdating = False

Sheets("Sheet1").Select
ActiveSheet.Range("D2:s28").Select
Selection.Copy
Windows("AnotherOpenFile.xls").Activate
Sheets("Sheet2").Select
ActiveSheet.Range("G1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Sheets("Sheet3").Select
'
Workbooks.OpenText Filename:="C:\MyPath\Myfile1.boo", Origin _
:=437, StartRow:=1, DataType:=xlFixedWidth,
FieldInfo:=Array(Array(0, 1), _
Array(2, 1), Array(5, 1), Array(8, 1), Array(12, 1), Array(16, 1),
Array(20, 1), Array(24, 1 _
), Array(28, 1), Array(32, 1), Array(36, 1), Array(40, 1),
Array(44,
1), Array(48, 1), Array _
(52, 1), Array(56, 1), Array(60, 1), Array(64, 1), Array(68, 1),
Array(72, 1), Array(76, 1), _
Array(80, 1), Array(84, 1), Array(88, 1), Array(92, 1), Array(96,
1), Array(100, 1)), _
TrailingMinusNumbers:=True
ActiveWindow.Close
Workbooks.OpenText Filename:="C:\MyPath\Myfile2.boo", Origin _
:=437, StartRow:=1, DataType:=xlFixedWidth,
FieldInfo:=Array(Array(0, 1), _
Array(2, 1), Array(5, 1), Array(8, 1), Array(12, 1), Array(16, 1),
Array(20, 1), Array(24, 1 _
), Array(28, 1), Array(32, 1), Array(36, 1), Array(40, 1),
Array(44,
1), Array(48, 1), Array _
(52, 1), Array(56, 1), Array(60, 1), Array(64, 1), Array(68, 1),
Array(72, 1), Array(76, 1), _
Array(80, 1), Array(84, 1), Array(88, 1), Array(92, 1), Array(96,
1), Array(100, 1)), _
TrailingMinusNumbers:=True
ActiveWindow.Close
Workbooks.OpenText Filename:="C:\MyPath\Myfile3.boo", Origin _
:=437, StartRow:=1, DataType:=xlFixedWidth,
FieldInfo:=Array(Array(0, 1), _
Array(2, 1), Array(5, 1), Array(8, 1), Array(12, 1), Array(16, 1),
Array(20, 1), Array(24, 1 _
), Array(28, 1), Array(32, 1), Array(36, 1), Array(40, 1),
Array(44,
1), Array(48, 1), Array _
(52, 1), Array(56, 1), Array(60, 1), Array(64, 1), Array(68, 1),
Array(72, 1), Array(76, 1), _
Array(80, 1), Array(84, 1), Array(88, 1), Array(92, 1), Array(96,
1), Array(100, 1)), _
TrailingMinusNumbers:=True
ActiveWindow.Close
'Application.ScreenUpdating = True
End Sub

The 3 files myfile1 myfile2 and myfile3 are all text files. I have to
open
them in order to get the values updated on anotheropenfile.xls. This part
was added as well as application.screenupdating true/false. The macro ran
fine before but now I get an error: "Automation Error Exception Occurred"
and
Excel shuts down. I can take out screenupdating true/false and it works
some
better but still shuts down occasionally. Reading the NG it seems as
though
that adding DoEvents may help, but I am unsure as how to do this. Can
some
one please advise?
Thanks!





All times are GMT +1. The time now is 03:56 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com