I have a couple macros that utilize the windows Common Dialog. These no longer work in Windows 7 but I haven't been able to find a good fix. Does anyone have suggestions?
I discovered a solution from another post that uses the GetOpenFileName function from the windows API. I like this the best so far.
I am assuming that this is a VBA macro? I am running Windows 7 and was able to successful add and use a common dialog control. Have you tried creating a new macro, inserting a common dialog control, and doing something very simple like if the user form is clicked, CommonDialog1.ShowOpen is run?
Video Tutorials for the SolidWorks API
Yes this is a VBA macro. I get a 429 error (see below)
This worked previously before Windows 7. I guess I'm not familiar with CommonDialog1. Though that's not saying much as I'm not proficient at all in VBA.
A bit of old school pontification...
In the days of VBA and VB6 and SW2003, CommonDialog was not licensed or available for SW macros. In order to get CommonDialog functions in macros, one needed to delve into the arcane world of Window API, declare a bunch of odd functions, and cut and paste a lot of code left posted by generous-hearted programmers.
Sometimes CommonDialog would work. This was deceptive. CommonDialog would work in a SW macro if one had a fully licensed version of CommonDialog working with some other application, such as the full version of VB6. However, the same macro would fail if it was run on a different workstation lacking benefit of said licensing.
Does it still matter? I don't know. My API kung fu gets rustier by the minute. But, perhap it does matter.
This should create a folder dialog as it is. Replace the 1 with 16384 as stated in the text and it should show the files.
Paste this into VBA and try it. Be sure to add the Shell control reference.
Hope this helps
'From Print drawings macro by T Sjoman Dec 21, 2011'Microsoft Shell Controls And Automation must be added to references
Function FolderSelection1(titleText As String) As String Dim MyPath As String MyPath = SelectFolder(titleText, "") If Len(MyPath) Then MsgBox MyPath Else MsgBox "Cancel was pressed" End If
Function SelectFolder(Optional Title As String, Optional TopFolder _As String) As String Dim objShell As New Shell32.Shell Dim objFolder As Shell32.Folder 'If you use 16384 instead of 1 on the next line,'files are also displayed Set objFolder = objShell.BrowseForFolder(0, Title, 1, TopFolder) If Not objFolder Is Nothing Then SelectFolder = objFolder.Items.Item.Path End IfEnd Function
Sub main() Dim FolderPath As String FolderPath = FolderSelection1("Please, Select a Folder!")End Sub
That works ok. Changing to include files worked, except that if I pick the file, I get this error:
"This Error" is (I can't upload the screenshot...ugh):
Run-time error '-2147467259 (80004005)': Automation ErrorUnspecified Error
Run-time error '-2147467259 (80004005)':
I actually found another solution I like better, as that dialog is a little limited in functionality. Thanks though for the tip, I will likely use it in the future.
Retrieving data ...