ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   To Bob Phillips ( Filesystem) (https://www.excelbanter.com/excel-programming/322583-bob-phillips-filesystem.html)

Alvin Hansen[_2_]

To Bob Phillips ( Filesystem)
 
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


Tom Ogilvy

To Bob Phillips ( Filesystem)
 
GetFolder is a variable.

if you want its contents in another variable then

Dim sStr as String
sStr = GetFolder


--
Regards,
Tom Ogilvy

"Alvin Hansen" wrote in message
...
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




Alvin Hansen[_2_]

To Bob Phillips ( Filesystem)
 
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 is a variable.

if you want its contents in another variable then

Dim sStr as String
sStr = GetFolder


--
Regards,
Tom Ogilvy

"Alvin Hansen" wrote in message
...
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





Tom Ogilvy

To Bob Phillips ( Filesystem)
 
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


--
Regards,
Tom Ogilvy

"Alvin Hansen" wrote in message
...
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 is a variable.

if you want its contents in another variable then

Dim sStr as String
sStr = GetFolder


--
Regards,
Tom Ogilvy

"Alvin Hansen" wrote in message
...
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







Alvin Hansen[_2_]

To Bob Phillips ( Filesystem)
 
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:

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


--
Regards,
Tom Ogilvy

"Alvin Hansen" wrote in message
...
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 is a variable.

if you want its contents in another variable then

Dim sStr as String
sStr = GetFolder


--
Regards,
Tom Ogilvy

"Alvin Hansen" wrote in message
...
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








Tom Ogilvy

To Bob Phillips ( Filesystem)
 
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


--
Regards,
Tom Ogilvy


"Alvin Hansen" wrote in message
...
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:

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


--
Regards,
Tom Ogilvy

"Alvin Hansen" wrote in message
...
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 is a variable.

if you want its contents in another variable then

Dim sStr as String
sStr = GetFolder


--
Regards,
Tom Ogilvy

"Alvin Hansen" wrote in

message
...
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










Alvin Hansen[_2_]

To Bob Phillips ( Filesystem)
 
Sorry sorry soryy
I have it now

Thanks for the help

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


--
Regards,
Tom Ogilvy

"Alvin Hansen" wrote in message
...
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 is a variable.

if you want its contents in another variable then

Dim sStr as String
sStr = GetFolder


--
Regards,
Tom Ogilvy

"Alvin Hansen" wrote in message
...
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









All times are GMT +1. The time now is 03:00 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com