ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Function GetActiveWindow Lib "user32" (https://www.excelbanter.com/excel-programming/296564-function-getactivewindow-lib-user32.html)

Jac Tremblay

Function GetActiveWindow Lib "user32"
 
Hi everyone
When we use this Windows API, the default "Folder" (it's not really a folder) that is selected in the window that appears is the user's workstation. Is there a way to change that default value to a known folder or to a specific path so that the user does not have to click many times to reach the desired path
I do not include any code, but it is all available if any one needs it. You just have to ask for it
Thank you.

Jake Marx[_3_]

Function GetActiveWindow Lib "user32"
 
Hi Jac,

You have a few options here. If you want to be able to specify the initial
folder, you can automate the Shell interface to do it:

Sub test()
Dim sh As Object
Dim fol As Object
Dim fi As Object

Set sh = CreateObject("Shell.Application")

Set fol = sh.BrowseForFolder(Application.Hwnd, _
"Select Folder", 0, "C:\")

If Not fol Is Nothing Then
Set fi = fol.ParentFolder.ParseName(fol.Title)
If Not fi Is Nothing Then
MsgBox fi.Path
Else
MsgBox fol.Title
End If
Set fol = Nothing
Else
MsgBox "no folder selected"
End If
End Sub

Alternatively, you can utilize the API using Jim Rech's Browse For Folder
utility:

http://bmsltd.ie/MVP/Default.htm (look for BrowseForFolder.zip under Jim
Rech's name)

--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

[please keep replies in the newsgroup - email address unmonitored]


Jac Tremblay wrote:
Hi everyone,
When we use this Windows API, the default "Folder" (it's not really a
folder) that is selected in the window that appears is the user's
workstation. Is there a way to change that default value to a known
folder or to a specific path so that the user does not have to click
many times to reach the desired path. I do not include any code, but
it is all available if any one needs it. You just have to ask for it.
Thank you.



Jac Tremblay

Function GetActiveWindow Lib "user32"
 
Hi Jake,
That is very interesting. I tried your code and it's rather straight forward. But how come one does not have to declare something like "Private Declare Function GetActiveWindow Lib "user32" () As Long" in the screen window code declaration section?
Another question: Why, when I create a new folder, I can specify its new name only at the root? If not at the root, the folder gets automatically the name "New Folder" with no feed back.
I will now check out Jim Rech's application.

Thank you very much.

Jake Marx[_3_]

Function GetActiveWindow Lib "user32"
 
Hi Jac,

Jac Tremblay wrote:
That is very interesting. I tried your code and it's rather straight
forward. But how come one does not have to declare something like
"Private Declare Function GetActiveWindow Lib "user32" () As Long" in
the screen window code declaration section?


This code is automating the Shell - it is not calling API functions (such as
GetActiveWindow) directly.

Another question: Why,
when I create a new folder, I can specify its new name only at the
root? If not at the root, the folder gets automatically the name "New
Folder" with no feed back.


I'm not sure what you're referring to here. Keep in mind that we can't see
your code unless you post it. <g

--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

[please keep replies in the newsgroup - email address unmonitored]


Jac Tremblay

Function GetActiveWindow Lib "user32"
 
Hi Jake
My question and your answer were
Another question: Why
when I create a new folder, I can specify its new name only at th
root? If not at the root, the folder gets automatically the name "Ne
Folder" with no feed back


I'm not sure what you're referring to here. Keep in mind that we can't se
your code unless you post it. <g

I now tell you that I have no more problem regarding this functionality. I can browse for a folder using the Shell Automation like you showed in your previous answer. I can create a new folder at the root or elsewhere and give it any name I want
The reason why I did not include any code is that I refered to your own code published in the previous answer
Thank you for providing me with this simple and easy way of browsing for a folder. It will be very useful
Thanks too for your precious time
Ja




All times are GMT +1. The time now is 08:37 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com