To Bob Phillips ( Filesystem)

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi Bob
I use the code you paste i a question i have before
"Filesystem again"
It is a Getfolder function
with this lines in last of the function
GetFolder = ""
If SHGetPathFromIDList(ByVal oDialog, ByVal path) Then
GetFolder = Left(path, InStr(path, Chr$(0)) - 1)
End If

Now i want to use this path in a
For
And
Next
So i have to have the value from getfolder into a variable
How do i do that?

Best regards Alvin
 
GetFolder is a variable.

if you want its contents in another variable then

Dim sStr as String
sStr = GetFolder
 
HI bob
Well if i use Gerfolder or
use str like you write
Dim sStr as String
sStr = GetFolder

then it run getfolder every time i run
in my
For and next
Like if i have
For i = 1 to 10
getfolder
next
then it run the function getfolder evry time
I want to run getfolder before i run my for and next
and here have the variable
like
Str = getfolder
for i = 1 to 10
Str
next
Hope you understand

Alvin


"Tom Ogilvy" skrev:
 
GetFolder isn't a function. In any event, run that code outside your loop.

GetFolder = ""
If SHGetPathFromIDList(ByVal oDialog, ByVal path) Then
GetFolder = Left(path, InStr(path, Chr$(0)) - 1)
sStr = GetFolder
End If

for i = 1 to 10

msgbox sStr
Next
 
Hi Tom I believe its because you don't have see all the code her it is:
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

'-------------------------------------------------------------
Function GetFolder(Optional ByVal Name As String = _
"Select a folder.") As String
'-------------------------------------------------------------
Dim bInfo As BROWSEINFO
Dim path As String
Dim oDialog As Long

bInfo.pidlRoot = 0& 'Root folder = Desktop

bInfo.lpszTitle = Name

bInfo.ulFlags = &H1 'Type of directory to Return
oDialog = SHBrowseForFolder(bInfo) 'display the dialog

'Parse the result
path = Space$(512)

GetFolder = ""
If SHGetPathFromIDList(ByVal oDialog, ByVal path) Then
GetFolder = Left(path, InStr(path, Chr$(0)) - 1)
End If

End Function











"Tom Ogilvy" skrev:
 
Yes, based on seeing the code, GetFolder is a Function. Without knowing
what you are doing, you just would call GetFolder above you loop, assigning
the results to a string variable (sStr below). Then utilize it inside you
loop if it is appropriate . . .


Dim sStr as String
sStr = GetFolder()
if sStr = "" then exit sub

for i = 1 to 10

' use sStr
Next


or if you are opening a single workbook and you want to process that
workbook inside you loop

Dim sStr as String
Dim bk as Workbook
sStr = GetFolder()
if sStr = "" then exit sub

set bk = Workbooks.Open(sStr)
for i = 1 to 10
if bk.Worksheets(1).Cells(i,1).Value = "ABCD" Then

End if
Next
 
Back
Top