|
-
Jun 8th, 2010, 02:07 PM
#1
Thread Starter
New Member
Last edited by RaytracerFFM; Jun 9th, 2010 at 05:19 PM.
-
Jun 10th, 2010, 02:58 AM
#2
Re: [EXCEL] Excel doesn't stay invisible after FileDialog closes. Really nobody???
Use the API's to solve your problem...
The following code is used for getting the folder name
Code:
Private Declare Function SHGetPathFromIDList Lib "shell32.dll" _
Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As String) As Long
Private Declare Function SHBrowseForFolder Lib "shell32.dll" _
Alias "SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) As Long
Private Type BROWSEINFO
hOwner As Long
pidlRoot As Long
pszDisplayName As String
lpszTitle As String
ulFlags As Long
lpfn As Long
lParam As Long
iImage As Long
End Type
Public Sub Test()
Dim FolderName As String
Application.Visible = False
FolderName = GetFolderName("Select a folder")
If FolderName = "" Then
MsgBox "You didn't select a folder."
Else
MsgBox "You selected this folder: " & FolderName
End If
Application.Wait (Now + TimeValue("0:00:03"))
Application.Visible = True
End Sub
Function GetFolderName(Msg As String) As String
Dim bInfo As BROWSEINFO, path As String, r As Long
Dim X As Long, pos As Integer
bInfo.pidlRoot = 0&
If IsMissing(Msg) Then
bInfo.lpszTitle = "Select a folder."
Else
bInfo.lpszTitle = Msg
End If
bInfo.ulFlags = &H1
X = SHBrowseForFolder(bInfo)
path = Space$(512)
r = SHGetPathFromIDList(ByVal X, ByVal path)
If r Then
pos = InStr(path, Chr$(0))
GetFolderName = Left(path, pos - 1)
Else
GetFolderName = ""
End If
End Function
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Jun 10th, 2010, 03:03 AM
#3
Re: [EXCEL] Excel doesn't stay invisible after FileDialog closes. Really nobody???
And the following to get the File Name
Code:
Private Declare Function SetCurrentDirectoryA Lib "kernel32" _
(ByVal lpPathName As String) As Long
Public Sub Test()
Dim sWBToOpen As Variant
Application.Visible = False
sWBToOpen = GetOpenFilenameFrom("c:\")
Application.Wait (Now + TimeValue("0:00:03"))
Application.Visible = True
End Sub
Public Function GetOpenFilenameFrom(Optional strDefDir As String) As Variant
Dim strCurDir As String, lngErr As Long
strCurDir = CurDir
If strDefDir = vbNullString Then
strDefDir = CurDir
Else
If Len(Dir(strDefDir, vbDirectory)) = 0 Then
strDefDir = strCurDir
End If
End If
If Not Left(strDefDir, 2) = "\\" Then
ChDrive Left(strDefDir, 1)
ChDir (strDefDir)
Else
lngErr = SetCurrentDirectoryA(strDefDir)
If lngErr = 0 Then _
MsgBox "Sorry, I encountered an error accessing the network file path"
ChDir (strDefDir)
End If
GetOpenFilenameFrom = Application.GetOpenFilename _
("Excel Files (*.xl*), *.xl*,All Files (*.*),*.*")
If Not Left(strCurDir, 2) = "\\" Then
ChDrive Left(strCurDir, 1)
ChDir (strCurDir)
Else
lngErr = SetCurrentDirectoryA(strCurDir)
If lngErr = 0 Then _
MsgBox "Error resetting the network file path"
ChDir (strCurDir)
End If
End Function
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Jun 10th, 2010, 03:25 AM
#4
Thread Starter
New Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|