Tom
Fri Jun 27 12:31:19 CDT 2008
On Jun 27, 11:31 am, scot <s...@discussions.microsoft.com> wrote:
> Hi:
>
> I've got a script that runs fine if I run it through the VB Editor, but
> won't run when done through a script. I'm not sure where I'm going wrong
> here, so if anyone has any ideas I'd appreciate it.
>
> Sub openexcel()
>
> Dim xlObj
>
> Set xlObj = CreateObject("excel.application")
> xlObj.Workbooks.Open "C:\Documents and Settings\****\My Documents\Import
> Tool.xls"
> xlObj.Run "Daily_Vol" 'This is the name of the macro w/in the Import Tool
> file saved as a Module
> xlObj.ActiveWorkbook.Saved = True
> xlObj.ActiveWindow.Close
> xlObj.Quit
> Set xlObj = Nothing
>
> End Sub
>
> Thanks
What do you mean by "won't run"? Nothing happens? It throws an
error? What?
If nothing happens, it's because you aren't telling the host to
actually run your subroutine. You see, as a script there must be a
'main program' outside of all subroutines and functions. It controls
the execution of the script application.
So, if you are not encountering an error, the solution may be as
simple as adding one line ...
openexcel ' invokes the subroutine
Sub openexcel()
...
sub end
If there is an error, you will need to tell us what it is (and which
line is reported as the source).
Tom Lavedas
===========
http://members.cox.net/tglbatch/wsh/