Opening CSV files (or Excel files) via a Macro


Posted by Tony Gill on November 21, 2001 6:54 PM

Trying to load 2 CSV formated files via a Macro.

Example of Macro below only loads the first file then stops??

Workbooks.Open Filename:="D:\FILES\EXCEL\DAD\RHPS\Filea.xls"
Workbooks.Open Filename:="D:\FILES\EXCEL\DAD\RHPS\Fileb.xls"
Windows("Macro.xls").Activate
ActiveCell.FormulaR1C1 = "Done"
Range("B5").Select

Example above is trying to load Excel sheets, but gives the same problem.

Hoping someone can help

Tony Gill

Posted by Varun Pant on November 21, 2001 8:04 PM

Try the following:
Workbooks.Open Filename:="D:\FILES\EXCEL\DAD\RHPS\Filea.xls"
Windows("Macro.xls").Activate
Workbooks.Open Filename:="D:\FILES\EXCEL\DAD\RHPS\Fileb.xls"
Windows("Macro.xls").Activate
ActiveCell.FormulaR1C1 = "Done"
Range("B5").Select



Posted by Tony Gill on November 22, 2001 12:54 PM

Varun,

Thanks for your very prompt response.
I believe I have already tried what you suggested, and it made no difference, however, what I have discovered is if you RUN the macro by selecting it, ie Tools/Macro/Macros Select the macro had select RUN, the macro runs ok!?!

This is not totally ideal, but close enough.

Many thanks anyway.

Tony.