I have the below portion of code in an excel 2010 vba. My question is how do I run the java process and wait until it completes before perl process is called?
' CALL JAVA PROGRAM USING SHELL '
Dim wshell As Object
Set wshell = CreateObject("wscript.shell")
wshell.Run Chr(34) & "C:\Users\cmccabe\Desktop\EmArray\Design\java.bat"
' UPDATE PERL VARIABLES '
Dim PerlCommand As String, PerlParameters As String
Dim var As String, var1 As String, var2 As String, var3 As String
var = MyDirectory
var1 = var & "sample_descriptor.txt"
var2 = "C:\cygwin\home\cmccabe\test_probes.txt"
var3 = var & "output.txt"
' CALL PERL '
PerlCommand = """C:\Users\cmccabe\Desktop\EmArray\Design\perl.bat"""
PerlParameters = """" & var & """" & " " & _
"""" & var1 & """" & " " & _
"""" & var2 & """" & " " & _
"""" & var3 & """"
CreateObject("wscript.shell").Run PerlCommand & " " & PerlParameters
edit: I just saw that post know and it solved my issue... thank you and I apologize, I had a variable named incorrectly :).
Related
I am getting an error on this line. Error 70: Permission Denied
wsh.Run """" & FileName & """"
I'm unsure what the problem is. This program is attempting to create a VB script inside to run asynchronously.
Private Sub CompleteUploadThread(ByVal fName As String)
Dim strScript As String, FileName As String, wsh As Object
Set wsh = VBA.CreateObject("WScript.Shell")
'---Create VBscript String---
strScript = "WScript.Sleep 1000" & vbCrLf & _
"Dim wsh" & vbCrLf & _
"Set wsh = CreateObject(""WScript.Shell"")" & vbCrLf & _
"wsh.SendKeys """ & fName & """" & vbCrLf & _
"wsh.SendKeys ""{ENTER}""" & vbCrLf & _
"Set wsh = Nothing"
'---Save the VBscript String to file---
FileName = wsh.ExpandEnvironmentStrings("C:\Users\x7user\Desktop\Temp") & "\automation.vbs"
Open FileName For Output As #1
Print #1, strScript
Close #1
'---Execute the VBscript file asynchronously---
wsh.Run """" & FileName & """"
Set wsh
here's the entire code snipet
Found the problem. It was a permission issues with the folder it was in. I have to use something I have admin access to.
When I am placing the code Excel file in a folder/directory which does not have any space in it the naming conventions than it is working fine and firing the Web-Service. But when I place the code Excel file in a folder which has space in it's naming convention, I am getting a run-time error:
'-2147024894 (80070002).
Please help
Sub InvokShellScript1()
Dim sApp As String
Dim var As Integer
sApp = ThisWorkbook.Path & "\protected\WSInvoke.bat " & ThisWorkbook.Path & "\protected\Refresh.txt " & ThisWorkbook.Path
Dim objShell As Object
Set objShell = CreateObject("WScript.Shell")
var = objShell.Run(sApp, 0, True)
End Sub
You need quotes around the paths to be able to handle spaces. Try either of these:
sApp = Chr$(34) & ThisWorkbook.Path & "\protected\WSInvoke.bat" & Chr$(34) & " " & Chr$(34) & ThisWorkbook.Path & "\protected\Refresh.txt" & Chr$(34) & " " & Chr$(34) & ThisWorkbook.Path & Chr$(34)
or if Chr() doesn't work:
sApp = """" & ThisWorkbook.Path & "\protected\WSInvoke.bat"" """ & ThisWorkbook.Path & "\protected\Refresh.txt"" """ & ThisWorkbook.Path & """"
This question already has an answer here:
Passing variables using excel macros in order to complete a sentence
(1 answer)
Closed 5 years ago.
I want to print the below output in my excel sheet rather than displaying on the msg box.
I have written the below code but I am not able to print the output of sCommand in my excel sheet.
I want to print the output on cell A1.
Thanks in advance.
sCommand = "Call " & s1 & "." & s2 & "(" & "'" & INPUT_DATE & "'" & "," & "'" &EXIT_DATE & "'" & "," & "STATUS " & ")" & ";"
MsgBox (sCommand)
Same as Gadziu, but instead of using .Cells(1,1) using .Range:
sCommand = "Call " & s1 & "." & s2 & "(" & "'" & INPUT_DATE & "'" & "," & "'" &EXIT_DATE & "'" & "," & "STATUS " & ")" & ";"
ActiveSheet.Range("A1").Value = sCommand
You should also declare which Sheet you are actually wanting to write to, as ActiveSheet will take the sheet that is currently selected/active, so this could be better defined as:
Sub foo()
Dim ws As Worksheet: Set ws = Sheets("Sheet1")
'declare and set your worksheet, amend as required
Dim s1 As String, s2 As String, sCommand As String
s1 = InputBox("Enter schema name")
s2 = InputBox("Enter procedure name")
Input_date = Format(Date, "dd/mm/yyyy") 'get today's date or: Input_date = InputBox("Enter Input Date")
Exit_Date = Format(Date, "dd/mm/yyyy") 'get today's date or: Exit_Date = InputBox("Enter Exit Date")
Status = InputBox("Status")
sCommand = "Call " & s1 & "." & s2 & "(" & "'" & Input_date & "'" & "," & "'" & Exit_Date & "'" & "," & Status & ")" & ";"
'concatenate your variables into a string
'ws.Cells(1, 1).Value = sCommand 'the Cells(1, 1) refer to Cells(row_number, column_number)
ws.Range("A1").Value = sCommand
End Sub
sCommand = "Call " & s1 & "." & s2 & "(" & "'" & INPUT_DATE & "'" & "," & "'" &EXIT_DATE & "'" & "," & "STATUS " & ")" & ";"
ActiveSheet.Cells(1,1).Value = sCommand
I'm working on Excel 11 Mac OS and below is the code I'm using for creating a folder
Function MakeFolderIfNotExist(Folderstring As String)
Dim ScriptToMakeFolder As String
Dim str As String
If Val(Application.Version) < 15 Then
ScriptToMakeFolder = "tell application " & Chr(34) & _
"Finder" & Chr(34) & Chr(13)
ScriptToMakeFolder = ScriptToMakeFolder & _
"do shell script ""mkdir -p "" & quoted form of posix path of (" & _
Chr(34) & Folderstring & Chr(34) & ")" & Chr(13)
ScriptToMakeFolder = ScriptToMakeFolder & "end tell"
On Error Resume Next
MacScript (ScriptToMakeFolder)
On Error GoTo 0
Else
str = MacScript("return POSIX path of (" & _
Chr(34) & Folderstring & Chr(34) & ")")
MkDir str
End If
End Function
After I call the function using
MakeFolderIfNotExist("/Desktop/test/2017")
I'm getting the error saying path not found. I've been searching the internet for good 2 hours now with no luck. can somebody please help?
I am trying to display the contents of a text file in notepad++ on the screen using line below the vba. Currently the rest of the vba runs and I can see the text file to be displayed in the directory var, which has the path to the directory, but only notepad++ opens and does not display the file. Is there a better way rather then Call Shell as I can not seem to fix this or what am I doing wrong? Thank you :).
vba
'UPDATE PERL VARIABLES USING SHELL '
Dim PerlCommand As String, PerlParameters As String, VarDirectory As String
Dim var As String, var1 As String, var2 As String, var3 As String
VarDirectory = "N:\path\to\data\" & "2571683" & MyBarCode & "_" & Format(CDate(MyScan), "m-d-yyyy")
var = VarDirectory
var1 = "sample_descriptor.txt"
var2 = "C:\cygwin\home\user\test_probes8.txt"
var3 = var & "\" & "output.txt"
var4 = var & "\" & "list_spikeins.txt" 'MATCH '
'CALL PERL '
PerlCommand = """C:\Users\user\Desktop\folder\file\perl.bat"""
PerlParameters = """" & var & """" & " " & _
"""" & var1 & """" & " " & _
"""" & var2 & """" & " " & _
"""" & var3 & """" & " " & _
"""" & var4 & """"
CreateObject("wscript.shell").Run PerlCommand & " " & PerlParameters, windowsStyle, waitOnReturn
MinutesElapsed = Format((Timer - StartTime) / 86400, "hh:mm:ss") 'SECONDS ELAPSED '
MsgBox "The ImaGene and the spike-in verification process completed in " & MinutesElapsed & " minutes" & " " & "these are the values:", vbInformation 'NOTIFY IN MINUTES '
Call Shell("C:\Program Files (x86)\Notepad++\Notepad++.exe " & "var" & "\" & "list_spikeins.txt", vbNormalFocus) ' DISPLAY IN NOTEPAD++ '