Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / New Users / August 2007

Tip: Looking for answers? Try searching our database.

Activate a macro within a folder

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
CAM - 06 Aug 2007 06:29 GMT
Hello,

I have about 20 workbooks each containing a macro called "ClearBalances"
within a folder called "Schedules"  The macro from each workbook clears the
quarter ending balances activated by a command button.  What I want to do is
to use the "ClearBalances" macro and clear out the balances without having
to open the workbook individually.  Is there a way to activate the
"ClearBlances" command button by using a seprate Excel sheet and press a
command button that will activate the "ClearBalance" macro.without having to
open all the worksbooks individually. Any suggestions or visit a website
will be appreciated.  Thank you in advance.
Dave Peterson - 06 Aug 2007 12:29 GMT
I think you'll have to open the workbooks--but you can do that work in a macro.

Maybe something like this untested, but compiled code:

Option Explicit
Sub testme01()
 
   Dim myNames() As String
   Dim fCtr As Long
   Dim myFile As String
   Dim myPath As String
   Dim TempWkbk As Workbook
   
   'change the folder here
   myPath = "C:\my documents\excel\test\Schedules"
   If myPath = "" Then Exit Sub
   If Right(myPath, 1) <> "\" Then
       myPath = myPath & "\"
   End If
   
   myFile = ""
   On Error Resume Next
   myFile = Dir(myPath & "*.xls")
   On Error GoTo 0
   If myFile = "" Then
       MsgBox "no files found"
       Exit Sub
   End If
   
   'get the list of files
   fCtr = 0
   Do While myFile <> ""
       fCtr = fCtr + 1
       ReDim Preserve myNames(1 To fCtr)
       myNames(fCtr) = myFile
       myFile = Dir()
   Loop

   If fCtr > 0 Then
       For fCtr = LBound(myNames) To UBound(myNames)
           Set TempWkbk = Workbooks.Open(Filename:=myPath & myNames(fCtr))
           Application.Run "'" & TempWkbk.Name & "'!ClearBalances"
           TempWkbk.Save
           TempWkbk.Close savechanges:=False
       Next fCtr
   End If
 
End Sub

> Hello,
>
[quoted text clipped - 7 lines]
> open all the worksbooks individually. Any suggestions or visit a website
> will be appreciated.  Thank you in advance.

Signature

Dave Peterson

CAM - 07 Aug 2007 01:35 GMT
Thanks Dave,
I will give it a try.

Cheers

>I think you'll have to open the workbooks--but you can do that work in a
>macro.
[quoted text clipped - 61 lines]
>> open all the worksbooks individually. Any suggestions or visit a website
>> will be appreciated.  Thank you in advance.

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.