Ride The Lightning
Board Regular
- Joined
- Jul 14, 2005
- Messages
- 238
Hi all,
I have a piece of code that allows me to display the contents of a particular folder in a column in excel. The purpose is to get a list of all the relevant excel files in the folder so I can run some other code using the files generated in the list. Here is 2 sections of code the main code uses to run:
The problem occurs on the 2nd section @ the line
(I posted the 1st section for context).
A few months ago, I upgraded from 32 to 64 bit excel (I had to due to size of files etc). I tried to update all the parts of the code that I researched would need updating such as adding "PtrSafe" on "Declare" statements and also added "Ptr" on to certain "Long" Variables. I really have no idea why it is crashing at this line but considering it was working fine on the 32 bit version, I am guessing that has something to do with it. Any help would be very much appreciated, as I have been stuck on this for some time.
I have a piece of code that allows me to display the contents of a particular folder in a column in excel. The purpose is to get a list of all the relevant excel files in the folder so I can run some other code using the files generated in the list. Here is 2 sections of code the main code uses to run:
Rich (BB code):
'64-bit API declarations
Declare PtrSafe Function SHGetPathFromIDList Lib "shell32.dll" _
Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As String) As Long
Declare PtrSafe Function SHBrowseForFolder Lib "shell32.dll" _
Alias "SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) As Long
Public Type BROWSEINFO
hOwner As LongPtr
pidlRoot As Long
pszDisplayName As String
lpszTitle As String
ulFlags As Long
lpfn As LongPtr
lParam As LongPtr
iImage As Long
End Type
Rich (BB code):
Function GetDirectory(Optional Msg) As String
Dim bInfo As BROWSEINFO
Dim path As String
Dim r As Long, x As Long, pos As Integer
' Root folder = Desktop
bInfo.pidlRoot = 0&
' Title in the dialog
If IsMissing(Msg) Then
bInfo.lpszTitle = "Select a folder."
Else
bInfo.lpszTitle = Msg
End If
' Type of directory to return
bInfo.ulFlags = &H1
' Display the dialog
x = SHBrowseForFolder(bInfo)
' Parse the result
path = Space$(512)
r = SHGetPathFromIDList(ByVal x, ByVal path)
If r Then
pos = InStr(path, Chr$(0))
GetDirectory = Left(path, pos - 1)
Else
GetDirectory = ""
End If
End Function
The problem occurs on the 2nd section @ the line
Rich (BB code):
r = SHGetPathFromIDList(ByVal x, ByVal path)
A few months ago, I upgraded from 32 to 64 bit excel (I had to due to size of files etc). I tried to update all the parts of the code that I researched would need updating such as adding "PtrSafe" on "Declare" statements and also added "Ptr" on to certain "Long" Variables. I really have no idea why it is crashing at this line but considering it was working fine on the 32 bit version, I am guessing that has something to do with it. Any help would be very much appreciated, as I have been stuck on this for some time.