#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 49
Default 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   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 225
Default 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   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 49
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Open each file in a folder and closing it Ayo Excel Discussion (Misc queries) 3 September 22nd 08 09:03 PM
how can i change my default working folder to a networked folder? wizard1154 Excel Discussion (Misc queries) 4 April 18th 07 07:29 PM
How to decide folder-depth or How to select more folders/subfolders (folder-tree) ? Subteam Excel Discussion (Misc queries) 2 May 7th 06 08:14 PM
Need code to save file to new folder, erase from old folder Ron M. Excel Discussion (Misc queries) 1 February 24th 06 06:02 PM
how can I specific a folder with wildcard criteria and excel will import all the correct files in that folder? Raven Excel Discussion (Misc queries) 1 January 24th 06 03:28 PM


All times are GMT +1. The time now is 11:32 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"