|
Prev: vbs question
Next: SQL Query in VBScript
From: scot on 27 Jun 2008 11:31 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
From: Tom Lavedas on 27 Jun 2008 13:31 On Jun 27, 11:31 am, scot <s...(a)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/
From: scot on 27 Jun 2008 14:14 Tom: "Won't run" meant that nothing happened. I put in the extra line "openexcel" and that did the trick. Thanks for your help. Scot
|
Pages: 1 Prev: vbs question Next: SQL Query in VBScript |