Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.misc
|
|||
|
|||
Closing folder
sub openfolder()
' I use this to open folder(ABC) Shell "explorer.exe " & Chr(34) & Environ("userprofile") & "\Desktop\ABC", vbNormalFocus end sub Can vba close the folder(ABC) also, can vba close a data.mht window Thanks |
#2
Posted to microsoft.public.excel.misc
|
|||
|
|||
Closing folder
Found the following code at http://www.andreavb.com/forum/viewtopic_5604.html
Replace Text1.text by ABC and run Sub cmdClose_Click() Declare Function FindWindow Lib "user32" Alias _ "FindWindowA" (ByVal lpClassName As String, _ ByVal lpWindowName As String) As Long Declare Function PostMessage Lib "user32" Alias _ "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, _ ByVal wParam As Long, lParam As Any) As Long Public Const WM_CLOSE = &H10 Private Sub cmdClose_Click() Dim winHwnd As Long Dim RetVal As Long winHwnd = FindWindow(vbNullString, Text1.Text) Debug.Print winHwnd If winHwnd < 0 Then RetVal = PostMessage(winHwnd, WM_CLOSE, 0&, 0&) If RetVal = 0 Then MsgBox "Error posting message." End If Else MsgBox Text1.Text + " is not open." End If End Sub "danpt" wrote: sub openfolder() ' I use this to open folder(ABC) Shell "explorer.exe " & Chr(34) & Environ("userprofile") & "\Desktop\ABC", vbNormalFocus end sub Can vba close the folder(ABC) also, can vba close a data.mht window Thanks |
#3
Posted to microsoft.public.excel.misc
|
|||
|
|||
Closing folder
Thank you very much, I learn something new.
"Sheeloo" wrote: Found the following code at http://www.andreavb.com/forum/viewtopic_5604.html Replace Text1.text by ABC and run Sub cmdClose_Click() Declare Function FindWindow Lib "user32" Alias _ "FindWindowA" (ByVal lpClassName As String, _ ByVal lpWindowName As String) As Long Declare Function PostMessage Lib "user32" Alias _ "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, _ ByVal wParam As Long, lParam As Any) As Long Public Const WM_CLOSE = &H10 Private Sub cmdClose_Click() Dim winHwnd As Long Dim RetVal As Long winHwnd = FindWindow(vbNullString, Text1.Text) Debug.Print winHwnd If winHwnd < 0 Then RetVal = PostMessage(winHwnd, WM_CLOSE, 0&, 0&) If RetVal = 0 Then MsgBox "Error posting message." End If Else MsgBox Text1.Text + " is not open." End If End Sub "danpt" wrote: sub openfolder() ' I use this to open folder(ABC) Shell "explorer.exe " & Chr(34) & Environ("userprofile") & "\Desktop\ABC", vbNormalFocus end sub Can vba close the folder(ABC) also, can vba close a data.mht window Thanks |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Open each file in a folder and closing it | Excel Discussion (Misc queries) | |||
how can i change my default working folder to a networked folder? | Excel Discussion (Misc queries) | |||
How to decide folder-depth or How to select more folders/subfolders (folder-tree) ? | Excel Discussion (Misc queries) | |||
Need code to save file to new folder, erase from old folder | Excel Discussion (Misc queries) | |||
how can I specific a folder with wildcard criteria and excel will import all the correct files in that folder? | Excel Discussion (Misc queries) |