Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,388
Default Help with Macro & Directory

Hi Guys,

I'm trying to run a macro that looks like this :

--------------------------------------------------------------------

Sub LoopMacroTest()
Dim lCount As Long
Dim wbResults As Workbook
Dim wbCodeBook As Workbook

Application.ScreenUpdating = False
Application.DisplayAlerts = False
Application.EnableEvents = False

On Error Resume Next

Set wbCodeBook = ThisWorkbook

With Application.FileSearch
..NewSearch
'Change path to suit
..LookIn = "C:\Documents and Settings\dhunter25\My Documents\Tests\GMS"
..FileType = msoFileTypeExcelWorkbooks
'.Filename = "Book*.xls"

If .Execute 0 Then 'Workbooks in folder
For lCount = 1 To .FoundFiles.Count 'Loop through all.
'Open Workbook x and Set a Workbook variable to it
Set wbResults = Workbooks.Open(.FoundFiles(lCount))


Columns("A:A").Select
Selection.Delete Shift:=xlToLeft
Rows("1:5").Select
Range("A5").Activate
Selection.Delete Shift:=xlUp
Columns("C:C").Select
Selection.Delete Shift:=xlToLeft
Range("D7").Select


wbResults.Close SaveChanges:=True


Next lCount
End If
End With

On Error GoTo 0
Application.ScreenUpdating = True
Application.DisplayAlerts = True
Application.EnableEvents = True
End Sub

-----------------------------------------------------------------------

The thing I want to edit is with regards to this line:

..LookIn = "C:\Documents and Settings\dhunter25\My Documents\Tests\GMS"



Rather than having a full directory path, i want to look in a folder called
GMS. This folder will be a subdirectory of the folder that this main macro
and workbook are stored in.

Can anyone tell me how to do this?



[If anyone wants to know, the macro will edit a folder full of excel
workbooks all at once by running a macro in another workbook]

Thanks!
Dave
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 5,441
Default Help with Macro & Directory

Dave,

Perhaps:

..LookIn = Thisworkbook.Path & "\GMS"


HTH,
Bernie
MS Excel MVP


"Dave" wrote in message
...
Hi Guys,

I'm trying to run a macro that looks like this :

--------------------------------------------------------------------

Sub LoopMacroTest()
Dim lCount As Long
Dim wbResults As Workbook
Dim wbCodeBook As Workbook

Application.ScreenUpdating = False
Application.DisplayAlerts = False
Application.EnableEvents = False

On Error Resume Next

Set wbCodeBook = ThisWorkbook

With Application.FileSearch
.NewSearch
'Change path to suit
.LookIn = "C:\Documents and Settings\dhunter25\My Documents\Tests\GMS"
.FileType = msoFileTypeExcelWorkbooks
'.Filename = "Book*.xls"

If .Execute 0 Then 'Workbooks in folder
For lCount = 1 To .FoundFiles.Count 'Loop through all.
'Open Workbook x and Set a Workbook variable to it
Set wbResults = Workbooks.Open(.FoundFiles(lCount))


Columns("A:A").Select
Selection.Delete Shift:=xlToLeft
Rows("1:5").Select
Range("A5").Activate
Selection.Delete Shift:=xlUp
Columns("C:C").Select
Selection.Delete Shift:=xlToLeft
Range("D7").Select


wbResults.Close SaveChanges:=True


Next lCount
End If
End With

On Error GoTo 0
Application.ScreenUpdating = True
Application.DisplayAlerts = True
Application.EnableEvents = True
End Sub

-----------------------------------------------------------------------

The thing I want to edit is with regards to this line:

.LookIn = "C:\Documents and Settings\dhunter25\My Documents\Tests\GMS"



Rather than having a full directory path, i want to look in a folder called
GMS. This folder will be a subdirectory of the folder that this main macro
and workbook are stored in.

Can anyone tell me how to do this?



[If anyone wants to know, the macro will edit a folder full of excel
workbooks all at once by running a macro in another workbook]

Thanks!
Dave



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
VB Code for a directory Marie Bayes Excel Discussion (Misc queries) 9 January 25th 07 01:12 PM
Macro - Open all word files in a directory Dileep Chandran Excel Worksheet Functions 11 December 19th 06 02:12 PM
Directory Jeff Excel Discussion (Misc queries) 1 October 5th 06 04:51 PM
Directory listing Bampah Excel Discussion (Misc queries) 4 January 19th 06 03:25 PM
How do I force an Excel macro to ask me which file and directory? Ramius Excel Discussion (Misc queries) 4 January 14th 05 03:26 PM


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