LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default Browse for folder - not selecting folder

It's not my code. I believe it's Chips.

Barb Reinhardt




"Trish Smith" wrote:

Hi everyone,

I found a previous message about browsing to a folder which was answered but
I've not been able to follow the steps that were taken.
http://www.microsoft.com/office/comm...7-d241d7a138d4

Now, I'm copying this bit from the thread because I don't understand what's
going on, sorry ! I've taken out some bits where it says which code is Chip
Pearson's and Barb Reinhardt's

Function BrowseFolder(Optional Caption As String = "") As String

Dim BrowseInfo As BrowseInfo
Dim FolderName As String
Dim ID As Long
Dim Res As Long

With BrowseInfo
.hOwner = 0
.pidlRoot = 0
.pszDisplayName = String$(MAX_PATH, vbNullChar)
.lpszINSTRUCTIONS = Caption
.ulFlags = BIF_RETURNONLYFSDIRS
.lpfn = 0
End With
FolderName = String$(MAX_PATH, vbNullChar)
ID = SHBrowseForFolderA(BrowseInfo)
If ID Then
Res = SHGetPathFromIDListA(ID, FolderName)
If Res Then
BrowseFolder = Left$(FolderName, InStr(FolderName, _
vbNullChar) - 1)
End If
End If

End Function

Dim myWB As Workbook
Dim AutoSecurity As MsoAutomationSecurity
'Dim myPath As String
Dim myName As String
Dim Path As String
Dim Prompt As String
Dim Title As String

Path = BrowseFolder("Select A Folder")
If Path = "" Then
Prompt = "You didn't select a folder. The procedure has been
canceled."
Title = "Procedure Canceled"
MsgBox Prompt, vbCritical, Title
Else
Prompt = "You selected the following path:" & vbNewLine & Path
Title = "Procedure Completed"
MsgBox Prompt, vbInformation, Title
End If

myName = Dir(Path)
Do
Debug.Print myName

AutoSecurity = Application.AutomationSecurity
Application.AutomationSecurity = msoAutomationSecurityLow
Set myWB = Workbooks.Open(myName)
Call UnprotectWB(myWB)
Application.AutomationSecurity = AutoSecurity
On Error Resume Next

myName = Dir ' Get next entry.
Loop While myName < ""

End Sub
Sub UnprotectWB(myWB As Workbook)
Dim myWS As Worksheet
'If worksheets are password protected, this won't work

myWB.Unprotect
For Each myWS In myWB.Worksheets
myWS.Unprotect
Next myWS
End Sub


Dave Peterson answered and said this
I'd do this:

after this line:
Path = BrowseFolder("Select A Folder")
if right(path,1) < "\" then
path = path & "\"
end if

Then for the dir statement:

myname = dir(mypath & "*.xls")

and also to not use VBA variable names but although I've tried to make
changes not sure doing right thing

myPath = BrowseFolder("Select A Folder") 'myPath = BrowseFolder("Select A
Folder")
If Right(myPath, 1) < "\" Then 'If myPath = "" Then
myFolderPath = myPath & "\"
Prompt = "You didn't select a folder. The procedure has been canceled."
Title = "Procedure Canceled"
MsgBox Prompt, vbCritical, Title
Else
Prompt = "You selected the following path:" & vbNewLine & myFolderPath
Title = "Procedure Completed"
MsgBox Prompt, vbInformation, Title
End If

myName = Dir(myFolderPath & "*.xls")

at the moment I get the messagebox saying I haven't selected a folder.

Can anyone help please

thank you

--
Trish

 
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
Browse for folder - not selecting folder Trish Smith Excel Programming 3 September 18th 08 09:23 AM
Browse for folder - not selecting folder Dave Peterson Excel Programming 1 September 17th 08 11:16 PM
Browse for folder Steph[_6_] Excel Programming 1 December 8th 05 04:53 PM
Browse for folder - Jim Rech's MD Excel Programming 4 February 8th 05 10:29 PM
Browse for folder MD Excel Programming 1 July 13th 04 01:23 PM


All times are GMT +1. The time now is 09:05 AM.

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

About Us

"It's about Microsoft Excel"