#1   Report Post  
Posted to microsoft.public.excel.misc
nc
 
Posts: n/a
Default Macro events

Hi

At present I am running a macro which list the files in a specified
directory on a worksheet using the following events,

Sub Worksheet_Activate()
Sub Worksheet_SelectionChange(ByVal Target As Range).

Can I run the macro whenever a file is saved to this directory?

Thanks.

  #2   Report Post  
Posted to microsoft.public.excel.misc
Arvi Laanemets
 
Posts: n/a
Default Macro events

Hi

Better use an UDF


Here are 3 UDF's, combining which allows you to list all files of certain
type in folder, the workbook is saved in, and/or in all of it's subfolders

Public Function GetSubfolder(MyFolder As String, FolderNum As Integer,
Optional MyTime As Date)
Dim fs, f, f1, s, sf
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder(MyFolder)
Set sf = f.SubFolders
i = 0
For Each f1 In sf
i = i + 1
If i = FolderNum Then GetSubfolder = f1.Name
Next
End Function

Public Function GetFileName(MyFolder As String, FileNum As Integer,
MyExtension As String, Optional MyTime As Date)
Dim fs, f, f1, fc, s
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder(MyFolder)
Set fc = f.Files
i = 0
For Each f1 In fc
If Right(f1.Name, 3) = MyExtension Then
i = i + 1
If i = FileNum Then GetFileName = f1.Name
End If
Next
End Function


Public Function GetThisFolder(Optional MyTime As Date)
GetThisFolder = ThisWorkbook.Path
End Function


--
Arvi Laanemets
( My real mail address: arvi.laanemets<attarkon.ee )



"nc" wrote in message
...
Hi

At present I am running a macro which list the files in a specified
directory on a worksheet using the following events,

Sub Worksheet_Activate()
Sub Worksheet_SelectionChange(ByVal Target As Range).

Can I run the macro whenever a file is saved to this directory?

Thanks.



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
Search, Copy, Paste Macro in Excel [email protected] Excel Worksheet Functions 0 January 3rd 06 06:51 PM
Editing a simple macro Connie Martin Excel Worksheet Functions 5 November 29th 05 09:19 PM
Closing File Error jcliquidtension Excel Discussion (Misc queries) 4 October 20th 05 12:22 PM
Playing a macro from another workbook Jim Excel Discussion (Misc queries) 1 February 23rd 05 10:12 PM
Date macro Hiking Excel Discussion (Misc queries) 9 February 3rd 05 12:40 AM


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