Issue
I am facing a peculiar issue.
I have a Folder Picker program which goes as follows:
Sub Select_Folder()
Dim SelectedFolder As String
' Open the select folder prompt
With Application.FileDialog(msoFileDialogFolderPicker)
If .Show = -1 Then ' if OK is pressed
SelectedFolder = .SelectedItems(1)
Else
Exit Sub ' User canceled
End If
End With
Worksheets("RawData").Cells(15, 34) = SelectedFolder
End Sub
I have a separate procedure to run Shell commands. Note that the two procedures do not share any variable names nor does the Shell function have any references to the output to the Folder Picker sub-procedure.
If I run the Shell script without running the Folder picker function, everything runs fine, the script is run from Command Prompt. If I run the Folder Picker function first, select a folder, and then try running the Shell function, it ends abruptly. It is only in the specific case of running the Folder Picker sub-procedure first that the Shell function doesn't work. Any suggestions what could cause this?
In both cases, the script is the same and if I try running it in CMD prompt, it runs perfectly fine.
Edit:
- When I say the prompt ends abruptly, I mean that the cmd window opens and closes within a second
- The script runs separately when called. This script runs command prompt to get information from an IBM server (The command is
"cmd.exe /S /C " & "cd " & IBMInstallationPath & " && scm show history -r " & "https://jazz-test4.conti.de/ccm4/" & " -u " & UserName & " -P " & Password & " -C " & Component & " -w " & StreamName & " --remotePath " & Chr(34) & Folder & Chr(34))
IBMPath = "C:\LegacyApp\IBM\EWM_Shell\3rd Party\scmtools\eclipse"
- As Tim Williams suggested, the CurDir was getting changed when I run the folder picker script to D drive. I have included a couple of more lines before running my Shell script(ChDrive and CurDrive) to change the current directory to C drive. It works fine now.
I am still not sure why though. Maybe because my IBM installation path is in C drive as well?
Solution
I would guess the folder picker changes the current directory (you can verify using Debug.Print CurDir
), and your script somehow relies on that being a specific path.
Answered By - Tim Williams Answer Checked By - Dawn Plyler (WPSolving Volunteer)