Hello
I wrote a macro (retrieving bits here and there) in order to do a batch export. However, the macro calls shell32.dll (for folder selection). On my computer, no problem with "Shell and Automation" enabled, but for my colleague, it shows an error on this line: "Set SH = New Shell32.Shell".
Error: The class does not support automation or the expected interface.
I'm on W7, him on W10, both in 64bit. Has anyone faced the same problem?
Thanks in advance,
The code snippet that crashes:
Function BrowseFolder(Optional Caption As String, _
Optional InitialFolder As String) As String
Dim SH As Shell32.Shell
Dim F As Shell32.Folder
Set SH = New Shell32.Shell
Set F = SH. BrowseForFolder(0&, Caption, BIF_RETURNONLYFSDIRS, InitialFolder)
If Not F Is Nothing Then
BrowseFolder = F.Items.Item.Path
End If
End Function
If I understood correctly, I just have to add 2 lines:
Dim obj as object
Set Obj = CreateObject("Shell.Application")
to do this?
Function BrowseFolder(Optional Caption As String, _
Optional InitialFolder As String) As String
Dim SH As Shell32.Shell
Dim F As Shell32.Folder
Dim ShellApp As Object
Set ShellApp = CreateObject("Shell.Application")
Set SH = New Shell32.Shell
Set F = SH. BrowseForFolder(0&, Caption, BIF_RETURNONLYFSDIRS, InitialFolder)
If Not F Is Nothing Then
BrowseFolder = F.Items.Item.Path
End If
End Function
Well no, it's as if you didn't do anything. You declare a ShellApp object to be a new Shell.Application object, but you continue to use your SH object.
Dim Folder As Object
Dim F As Folder
Dim ShellApp As Object
Set ShellApp = CreateObject("Shell.Application")
Set F = ShellApp.BrowseForFolder(0&, Caption, BIF_RETURNONLYFSDIRS, InitialFolder)
If Not F Is Nothing Then
BrowseFolder = F.Items.Item.Path
End If
Kind regards
1 Like
Ah, after modification, the macro crashes solidworks now. Any idea?
In time for me, problem solved, thank you