Monday, 30 September 2013

VBA Objected Required Error

VBA Objected Required Error

I have a function that creates a text file for the directory location and
then calls a batch script that I wrote. I keep getting the object required
error and am having difficulty troubleshooting it.
Sub fncNewDirectoryLocation()
Set sC = Sheets("Control")
Dim FolderName As String
With Application.FileDialog(msoFileDialogFolderPicker)
.AllowMultiSelect = False
.Show
On Error Resume Next
FolderName = .SelectedItems(1)
Err.Clear
On Error GoTo 0
End With
fncDeleteDirectoryLocation
fncCreateDirectoryLocation (FolderName)
fncCallExtractAndDelete
End Sub
Sub fncDeleteDirectoryLocation()
On Error Resume Next
Kill (ThisWorkbook.Path & "\drive_path.txt")
End Sub
Sub fncCreateDirectoryLocation(folderLocation As String)
Set FS = CreateObject("Scripting.FileSystemObject")
Set a = FS.CreateTextFile(ThisWorkbook.Path & "\drive_path.txt", True)
a.WriteLine (folderLocation)
a.Close
End Sub
Sub fncShellAndWait(script As String)
Dim cmdline As String: cmdline = "cmd.exe /k " & """" & "cd /d " & "" &
Environ("temp") & " && " & script & """"
Dim x As Integer
x = ShellAndWait.ShellAndWait(cmdline, 21600000, vbMinimizedFocus,
AbandonWait)
End Sub
Sub fncCallExtractAndDelete()
fncShellAndWait ("ExtractAndDelete.bat")
End Sub

No comments:

Post a Comment