Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Specifying work-path

Is there a way of doing a macro of VBscript that you can select what folder
that contains your .xls files and save it into a variable?

explanation,

macro 1 = specify path to all .xls files
macro 2= copys cells A1- A7 from all .xls files in that folder

I've got the second macro worked out thanks to Ron de Bruins site but i cant
really get a working macro to specify a workpath easy.

Another alternative is that you could write the path inside a Cell and then
the macro claims that line, but i dont know how to do this either.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,092
Default Specifying work-path

The following Declarations and Function will let you browse to a folder and
select it. The short macro at the bottom (FolderPath) will use this function
to assign the path of the folder you select to the string variable FPath.

Option Explicit
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

Sub FolderPath()
Dim FPath as String
FPath = GetFolder
End Sub

Mike F
"Tobie" wrote in message
...
Is there a way of doing a macro of VBscript that you can select what
folder
that contains your .xls files and save it into a variable?

explanation,

macro 1 = specify path to all .xls files
macro 2= copys cells A1- A7 from all .xls files in that folder

I've got the second macro worked out thanks to Ron de Bruins site but i
cant
really get a working macro to specify a workpath easy.

Another alternative is that you could write the path inside a Cell and
then
the macro claims that line, but i dont know how to do this either.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Specifying work-path

Worked out excactly the way i wanted, perfect!


"Mike Fogleman" wrote:

The following Declarations and Function will let you browse to a folder and
select it. The short macro at the bottom (FolderPath) will use this function
to assign the path of the folder you select to the string variable FPath.

Option Explicit
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

Sub FolderPath()
Dim FPath as String
FPath = GetFolder
End Sub

Mike F
"Tobie" wrote in message
...
Is there a way of doing a macro of VBscript that you can select what
folder
that contains your .xls files and save it into a variable?

explanation,

macro 1 = specify path to all .xls files
macro 2= copys cells A1- A7 from all .xls files in that folder

I've got the second macro worked out thanks to Ron de Bruins site but i
cant
really get a working macro to specify a workpath easy.

Another alternative is that you could write the path inside a Cell and
then
the macro claims that line, but i dont know how to do this either.




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
Auto PRINT file path & Date on Excel work sheet ? Harsh Excel Worksheet Functions 1 October 24th 08 04:18 PM
Moved file, changed path, macros don't work donbowyer Excel Programming 3 May 22nd 06 08:27 AM
hyperlink navigation path path wrong in Excel 2003 CE Admin Excel Discussion (Misc queries) 5 January 7th 06 07:47 PM
Change Path names in copied work book jheaney Excel Worksheet Functions 2 November 18th 04 07:29 PM
Import text file without specifying a path macro won't work Bruiser Excel Programming 3 January 20th 04 11:47 PM


All times are GMT +1. The time now is 07:16 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"