I have a routine that I run to unload the current VBA on exit. The routine works with no problem except it comes back with the “Execution error”. Evidently this has been a problem for some time since I was reading other posts. I know it is because it unloading itself before the end of the sub. If I use the send command VBAUnload it doesn’t let the user restart the command by typing enter. It comes up with the VBAununload command.
Sub ExitOut()
On Error Resume Next
Set objNetwork = CreateObject("WScript.Network")
Set colDrives = objNetwork.EnumNetworkDrives
CurrentVBA = Application.VBE.ActiveVBProject.FileName
For i = 0 To colDrives.Count - 1
Drive = colDrives.Item(i)
UNC = colDrives.Item(i + 1)
CurrentVBA = Replace(CurrentVBA, UNC, Drive, 1, -1, 1)
Next
UnloadDVB CurrentVBA
End Sub
Thanks in advance for any help.
Solved! Go to Solution.
Solved by Jedimaster. Go to Solution.
The short answer is don't do that. All that enter does is run the last command which was VBAUNload
Yes I am aware that exicutes the last comand. Send command VBAUnload makes VBAUnload the last command.
UnloadDVB is transparent. The routine works fine with UnloadDVB it works fine just has that stupid error message at the end. The funny thing is if I run it through the VBAMAN it does not give me that error. It is only if the rounite is run from the command prompt that it kicks back the error.
Finally got rid of the exicution error. Not as pretty a little noisy but no error.
ThisDrawing.SendCommand "vbaunload" & vbCr & Chr(34) & Application.VBE.ActiveVBProject.FileName & Chr(34) & vbCr