Hey guys, I'm having a weird problem with the call shell function of VBA. When the function executes, a command prompt pops up for a few seconds, then closes despite the '/k' in my code. When I double click the exe I'm calling it works fine. When I run it from within a command prompt it works fine.
Code:
Private Sub Command13_Click()
Dim strPath As String
Dim export As String
Dim i As Integer
Dim varitem As Variant
export = ""
strPath = "C:\Text\test3.csv"
i = 1
For Each varitem In Me.List0.ItemsSelected
'iterates through items selected in list and for each non-blank item adds it to a comma separated string
If (Me.List0.Column(7, varitem)) <> "" And i <> Me.List0.ItemsSelected.Count Then
export = export & Me.List0.Column(7, varitem) & ","
i = i + 1
'ensures the last number isn't followed with a comma
ElseIf (Me.List0.Column(7, varitem)) <> "" And i = Me.List0.ItemsSelected.Count Then
export = export & Me.List0.Column(7, varitem)
i = i + 1
'progresses iteration through list if item is blank without messing up formatting of the string
Else
i = i + 1
End If
Next varitem
'deletes old file if it exists
If Dir(strPath) <> "" Then
Kill (strPath)
End If
Dim fs As Object
Dim a As Object
Set fs = CreateObject("Scripting.FileSystemObject")
Set a = fs.CreateTextFile(strPath)
a.writeline (export)
Call Shell("C:\Text\text.exe /k", vbNormalFocus)
End Sub
The code writes info to a csv file, then calls an exe which accesses the exe file. Any thoughts?