RunFromTemp

Check if an Excel file is running from 'Temp' location or regular folder
This happens if user doubled-click an Excel tool from inside zip, from inside an email, or from a shared network location
Then shows an error message if it is, message can be passed in parameters
Option to show message or not can be passed, in addition option to Exit tool after that message can be passed
Most of times, user just double click a file inside an email message or a zip file
Windows then extract that file from the email or zip file into a temporary location
Usually that folder is: C:\Users\{{USERNAME}}\AppData\Local\Temp in Win Vista and 7
Then open the file from there, that is when some problems are showing if the developer do not expect that.

CodeFunctionName
What is this?

Public

Tested

Original Work
Function RunFromTemp(Optional WithMsg = 0, Optional Msg = "", Optional ThenExit = 1) As Boolean
' Check if an Excel file is running from 'Temp' location or regular folder
' And shows an error message if it is...
RunFromTemp = False
mypath = ThisWorkbook.Path
If InStr(1, mypath, "\AppData\Local\Temp\", vbTextCompare) > 0 Then
' Can not run file from temp location
' Please save the file first into a proper location, then run it from there
RunFromTemp = True
If WithMsg > 0 Then
If Msg = "" Then Msg = "You cannot run this tool from an email, or a " & _
"zip archive that uses a temporary location." & vbCrLf & vbCrLf & _
"Please save the tool (or extract it) to local drive then run it from there." & vbCrLf & "Thanks"
MsgBox Msg,vbcritical
End If
If ThenExit = 1 Then ThisWorkbook.Close False
End If
End Function

Optional WithMsg, Optional Msg, Optional ThenExit

Views 3,092

Downloads 1,266

CodeID
DB ID