Cześć,
mam macro w Excelu:
Sub CreateAfile(Optional inputfolder, Optional outputfolder, Optional ExitCode)
Dim fs As Object
Dim a As Object
Set fs = CreateObject("Scripting.FileSystemObject")
'' inputfolder = "C:\Users\admin\Desktop\Newest Pull request\VBScriptTests\input\"
If Len(Dir(inputfolder, vbDirectory)) = 0 Then
MkDir inputfolder
End If
'' outputfolder = "C:\Users\admin\Desktop\Newest Pull request\VBScriptTests\output\"
If Len(Dir(outputfolder, vbDirectory)) = 0 Then
MkDir outputfolder
End If
Set a = fs.CreateTextFile(inputfolder & "test.txt", True)
a.WriteLine ("This is a test.")
a.Close
fs.CopyFile inputfolder & "test.txt", outputfolder
If Len(ExitCode) = 0 Then
ExitCode = 0
End If
End Sub
proste makro.
I teraz mam VBSript:
Option Explicit
On Error Resume Next
ExcelMacroIntegration
Sub ExcelMacroIntegration()
Dim exitCode
Dim inputFolder
Dim outputFolder
inputFolder = "C:\Users\admin\Desktop\Newest Pull request\VBScriptTests\input\"
outputFolder = "C:\Users\admin\Desktop\Newest Pull request\VBScriptTests\output\"
Dim xlApp
Dim XlBook
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Open("C:\Users\admin\Desktop\Newest Pull request\VBScriptTests\Book1.xlsm", 0, True)
xlApp.Visible = True
xlApp.Run "CreateAfile", inputFolder, outputFolder, exitCode
xlApp.Quit
Set xlBook = Nothing
Set xlApp = Nothing
wscript.Quit(exitCode)
End Sub
gdzie mam exitCode jako parameter.
I to co mam w excelu w makrze zostanie przekazane dalej .
Czyli jak mam ExitCode = 2 w Excelu to wscript.quit(exitCode) to tutaj ExitCode = 2 również.
Dlaczego?
W excelu to nie funkcja zwracajaca argument tylko procedura Sub...
Aby przetestować uzywam innego vbscripta:
Set oWS = WScript.CreateObject("WScript.Shell")
returnCode = oWS.Run("wscript.exe RunTest.vbs", 0, True)
MsgBox "Script2's Return Code: " & returnCode
PRośba o wyjaśnienie dlaczego to działa?