Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Jac Jac is offline
external usenet poster
 
Posts: 58
Default How to look for the Folder Path using macro????

Hi,

I would like to save some files in a particular folder, for example
(Ven_Folder) in my computer system; but this folder may be transffered to
another directory time after time. So instead of using the absolute path to
fix the file saving location; I would pretty much wish that there could have
a way the macro can help to lookup for the folder path before those mentioned
files are saved.

I have tried out the Dir statement but it can only work in the 1st loop in
looping control structure. Thus, anyone can help in this matter.......????

Thanking in advanced.



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 340
Default How to look for the Folder Path using macro????

If any of the workbooks you have open are from this directory, then if you
activate one of them, activeworkbook.path will return the path to the
directory.

Bob Flanagan
Macro Systems
http://www.add-ins.com
Productivity add-ins and downloadable books on VB macros for Excel

"Jac" wrote in message
...
Hi,

I would like to save some files in a particular folder, for example
(Ven_Folder) in my computer system; but this folder may be transffered to
another directory time after time. So instead of using the absolute path
to
fix the file saving location; I would pretty much wish that there could
have
a way the macro can help to lookup for the folder path before those
mentioned
files are saved.

I have tried out the Dir statement but it can only work in the 1st loop in
looping control structure. Thus, anyone can help in this matter.......????

Thanking in advanced.





  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default How to look for the Folder Path using macro????

Hi Jac

You can browse to the folder you want

Dim Fld As Object
Dim foldername As String
Set Fld = CreateObject("Shell.Application").BrowseForFolder( 0, "Select folder", 512)
If Not Fld Is Nothing Then
foldername = Fld.Self.Path
If Right(foldername, 1) < "\" Then
foldername = foldername & "\"
End If
End If

Now you can use foldername ib you save path



--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"Jac" wrote in message ...
Hi,

I would like to save some files in a particular folder, for example
(Ven_Folder) in my computer system; but this folder may be transffered to
another directory time after time. So instead of using the absolute path to
fix the file saving location; I would pretty much wish that there could have
a way the macro can help to lookup for the folder path before those mentioned
files are saved.

I have tried out the Dir statement but it can only work in the 1st loop in
looping control structure. Thus, anyone can help in this matter.......????

Thanking in advanced.



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default How to look for the Folder Path using macro????

Or maybe this...
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware
(color sort, compare, unique, thesaurus and other add-ins)


Sub DoesItExist()
Call IsFolderThere("*Connection*", "C:\Program Files")
End Sub

Private Function IsFolderThere(ByRef strFolder As String, _
ByRef strPath As String) As Boolean
'Jim Cone - San Francisco, USA - May 2006
'Requires project reference to "Microsoft Scripting Runtime" library
'Not recommended to search an entire drive, unless additional code is
'created to handle the error from the System Volume folder.
'Determines whether a folder exists in a specific path.
On Error GoTo ScriptErr
Dim objFSO As Scripting.FileSystemObject
Dim objFolder As Scripting.Folder
Dim strMsg As String

Application.StatusBar = "FINDING FOLDER"
'Bring it to life...
Set objFSO = New Scripting.FileSystemObject

'Check for top folder
On Error Resume Next
Set objFolder = objFSO.GetFolder(strPath)
If Err.Number < 0 Then
MsgBox "No Top Folder:"
GoTo FinishUp
End If
On Error GoTo ScriptErr

'Check all of the sub folders.
Call CheckSubFolders(objFolder.SubFolders, strFolder, strMsg)
If Len(strMsg) Then
MsgBox "Folder path is: " & strMsg
Else
MsgBox "Cannot find folder " & strFolder & " "
End If
FinishUp:
On Error Resume Next
Application.StatusBar = False
Set objFSO = Nothing
Set objFolder = Nothing
Exit Function

ScriptErr:
MsgBox "Error " & Err.Number & " " & Err.Description
GoTo FinishUp
End Function

'Recursive function calls itself in order to scan subfolder folders.
Private Function CheckSubFolders(ByRef sFolders As Scripting.Folders, _
ByRef strFolder As String, ByRef strMsg As String) As Boolean
Dim objSubFolder As Scripting.Folder
Dim strPath As String
For Each objSubFolder In sFolders
If objSubFolder.Name Like strFolder Then
strMsg = objSubFolder.Path & " "
Exit Function
ElseIf Len(strMsg) = 0 Then
Call CheckSubFolders(objSubFolder.SubFolders, strFolder, strMsg)
End If
Next 'objsubfolder
Set objSubFolder = Nothing
End Function
'------------------


"Jac"
wrote in message
Hi,
I would like to save some files in a particular folder, for example
(Ven_Folder) in my computer system; but this folder may be transffered to
another directory time after time. So instead of using the absolute path to
fix the file saving location; I would pretty much wish that there could have
a way the macro can help to lookup for the folder path before those mentioned
files are saved.

I have tried out the Dir statement but it can only work in the 1st loop in
looping control structure. Thus, anyone can help in this matter.......????

Thanking in advanced.



  #5   Report Post  
Posted to microsoft.public.excel.programming
Jac Jac is offline
external usenet poster
 
Posts: 58
Default How to look for the Folder Path using macro????

Thanks for your solution; will try it out!
; )

"Bob Flanagan" wrote:

If any of the workbooks you have open are from this directory, then if you
activate one of them, activeworkbook.path will return the path to the
directory.

Bob Flanagan
Macro Systems
http://www.add-ins.com
Productivity add-ins and downloadable books on VB macros for Excel

"Jac" wrote in message
...
Hi,

I would like to save some files in a particular folder, for example
(Ven_Folder) in my computer system; but this folder may be transffered to
another directory time after time. So instead of using the absolute path
to
fix the file saving location; I would pretty much wish that there could
have
a way the macro can help to lookup for the folder path before those
mentioned
files are saved.

I have tried out the Dir statement but it can only work in the 1st loop in
looping control structure. Thus, anyone can help in this matter.......????

Thanking in advanced.








  #6   Report Post  
Posted to microsoft.public.excel.programming
Jac Jac is offline
external usenet poster
 
Posts: 58
Default How to look for the Folder Path using macro????

Thanks for your solution and will try it out in my coding!
: )

"Ron de Bruin" wrote:

Hi Jac

You can browse to the folder you want

Dim Fld As Object
Dim foldername As String
Set Fld = CreateObject("Shell.Application").BrowseForFolder( 0, "Select folder", 512)
If Not Fld Is Nothing Then
foldername = Fld.Self.Path
If Right(foldername, 1) < "\" Then
foldername = foldername & "\"
End If
End If

Now you can use foldername ib you save path



--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"Jac" wrote in message ...
Hi,

I would like to save some files in a particular folder, for example
(Ven_Folder) in my computer system; but this folder may be transffered to
another directory time after time. So instead of using the absolute path to
fix the file saving location; I would pretty much wish that there could have
a way the macro can help to lookup for the folder path before those mentioned
files are saved.

I have tried out the Dir statement but it can only work in the 1st loop in
looping control structure. Thus, anyone can help in this matter.......????

Thanking in advanced.




  #7   Report Post  
Posted to microsoft.public.excel.programming
Jac Jac is offline
external usenet poster
 
Posts: 58
Default How to look for the Folder Path using macro????

Thanks for your solution and will try it out later!
: )

"Jim Cone" wrote:

Or maybe this...
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware
(color sort, compare, unique, thesaurus and other add-ins)


Sub DoesItExist()
Call IsFolderThere("*Connection*", "C:\Program Files")
End Sub

Private Function IsFolderThere(ByRef strFolder As String, _
ByRef strPath As String) As Boolean
'Jim Cone - San Francisco, USA - May 2006
'Requires project reference to "Microsoft Scripting Runtime" library
'Not recommended to search an entire drive, unless additional code is
'created to handle the error from the System Volume folder.
'Determines whether a folder exists in a specific path.
On Error GoTo ScriptErr
Dim objFSO As Scripting.FileSystemObject
Dim objFolder As Scripting.Folder
Dim strMsg As String

Application.StatusBar = "FINDING FOLDER"
'Bring it to life...
Set objFSO = New Scripting.FileSystemObject

'Check for top folder
On Error Resume Next
Set objFolder = objFSO.GetFolder(strPath)
If Err.Number < 0 Then
MsgBox "No Top Folder:"
GoTo FinishUp
End If
On Error GoTo ScriptErr

'Check all of the sub folders.
Call CheckSubFolders(objFolder.SubFolders, strFolder, strMsg)
If Len(strMsg) Then
MsgBox "Folder path is: " & strMsg
Else
MsgBox "Cannot find folder " & strFolder & " "
End If
FinishUp:
On Error Resume Next
Application.StatusBar = False
Set objFSO = Nothing
Set objFolder = Nothing
Exit Function

ScriptErr:
MsgBox "Error " & Err.Number & " " & Err.Description
GoTo FinishUp
End Function

'Recursive function calls itself in order to scan subfolder folders.
Private Function CheckSubFolders(ByRef sFolders As Scripting.Folders, _
ByRef strFolder As String, ByRef strMsg As String) As Boolean
Dim objSubFolder As Scripting.Folder
Dim strPath As String
For Each objSubFolder In sFolders
If objSubFolder.Name Like strFolder Then
strMsg = objSubFolder.Path & " "
Exit Function
ElseIf Len(strMsg) = 0 Then
Call CheckSubFolders(objSubFolder.SubFolders, strFolder, strMsg)
End If
Next 'objsubfolder
Set objSubFolder = Nothing
End Function
'------------------


"Jac"
wrote in message
Hi,
I would like to save some files in a particular folder, for example
(Ven_Folder) in my computer system; but this folder may be transffered to
another directory time after time. So instead of using the absolute path to
fix the file saving location; I would pretty much wish that there could have
a way the macro can help to lookup for the folder path before those mentioned
files are saved.

I have tried out the Dir statement but it can only work in the 1st loop in
looping control structure. Thus, anyone can help in this matter.......????

Thanking in advanced.




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
Path and Number of files in a folder. - Pass to Macro. Richard Excel Discussion (Misc queries) 1 December 21st 06 09:20 PM
How to List the names of the subfolders present in the folder (path of folder is given in the textbox by user ) divya Excel Programming 3 November 30th 06 11:34 AM
Setting a path to a folder Boots Excel Discussion (Misc queries) 2 August 10th 06 02:14 PM
Get Folder Path RNM[_2_] Excel Programming 1 August 8th 04 03:19 AM
find if there is a particular folder in a path nikolaosk[_11_] Excel Programming 2 October 20th 03 08:22 AM


All times are GMT +1. The time now is 06:38 PM.

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"