Created
May 10, 2016 18:41
-
-
Save darkdreamingdan/19424d249d928d166fc2a38a2b17d12d to your computer and use it in GitHub Desktop.
Grab the path of an OLE temp file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Function GetOLETempPath(obj As OLEObject) As String | |
Dim B() As Byte, Pos&, iEnd&, iStart&, iLength& | |
Dim Header As String | |
obj.Copy ' (49156 = Native format) | |
If Not GetData(49156, B) Then Exit Function | |
Dim Buffer$, FileName$, Extension$ | |
Buffer = StrConv(B, vbUnicode) | |
Header = Chr$(0) & Chr$(0) & Chr$(3) & Chr$(0) | |
Pos = InStr(Buffer, Header) | |
' To do: probably check if we reached EOF | |
If Pos Then | |
iStart = Pos + 8 | |
iEnd = InStr(iStart + 1, Buffer, Chr$(0)) + 1 'Inc Null terminator | |
'iEnd = iStart + 10 | |
iLength = iEnd - iStart | |
End If | |
GetOLETempPath = Mid(Buffer, iStart, iLength) | |
Debug.Print (GetOLETempPath) | |
If Len(Dir(GetOLETempPath)) = 0 Then | |
GetOLETempPath = "" | |
End If | |
End Function |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment