Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 30th, 2007, 03:43 AM
Authorized User
 
Join Date: Mar 2007
Location: , , .
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default Run same marco in several files together

I would like to know is it possible to run serveral files in one time, now i have a problem I need to open by file and file and use the same marco to run these files.




Reply With Quote
  #2 (permalink)  
Old March 30th, 2007, 03:53 AM
Friend of Wrox
Points: 3,060, Level: 23
Points: 3,060, Level: 23 Points: 3,060, Level: 23 Points: 3,060, Level: 23
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2005
Location: , , .
Posts: 812
Thanks: 1
Thanked 53 Times in 49 Posts
Default

Hi

You can use the following code to execute the macro in all Excel (.xls) files under a given folder. You can tweek a bit if necessary

Sub Exec_Macro_For_All()

Dim sPath As String
Dim sFile As String
Dim sDir As String
Dim oWB As Workbook
Dim i1 As Long
Dim iMax As Long

On Error GoTo Err_Clk

sPath = "" ' Your Path
If Right$(sPath, 1) <> "\" Then sPath = sPath & "\"

sDir = Dir$(sPath & "*.xls", vbNormal)
Do Until LenB(sDir) = 0
       Set oWB = Workbooks.Open(sPath & sDir)
       Exec_MyMacro() ' Your MAcro here
       oWB.Save
       oWB.Close False
    sDir = Dir$
Loop

Err_Clk:
If Err <> 0 Then
    Err.Clear
    Resume Next
End If
End Sub

Cheers
Shasur

http://www.vbadud.blogspot.com
Reply With Quote
  #3 (permalink)  
Old April 4th, 2007, 01:09 AM
Authorized User
 
Join Date: Mar 2007
Location: , , .
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Dear Shasur,

Thank you very much!

I want to know one more thing.
One kind of my incoming data is in text file format and I need to open in excel then I choose delimited, comma and treat consecutive delimiters as one. Then I start to run the macro.

So is it possible to run another marco and complete "delimited, comma and treat consecutive delimiters as one" for these incoming text file?

Thanks and with Best Regards,
Ivan


Reply With Quote
  #4 (permalink)  
Old April 4th, 2007, 01:16 AM
Friend of Wrox
Points: 3,060, Level: 23
Points: 3,060, Level: 23 Points: 3,060, Level: 23 Points: 3,060, Level: 23
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2005
Location: , , .
Posts: 812
Thanks: 1
Thanked 53 Times in 49 Posts
Default

You can very well do that Ivan

You can have another function to import or open the text file and you can use both this function and the other macro run for all files

Cheers
Shasur

http://www.vbadud.blogspot.com
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
The "GALLERY" add-on for the marco basecode krainov BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 3 March 21st, 2008 04:07 AM
Write Files in another Domain (Run in Client) Maritza ASP.NET 2.0 Professional 1 February 26th, 2008 01:16 PM
Tip for Marco on next version MythicalMe BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 0 May 22nd, 2006 01:26 PM
error when i try to run these files, anyone? anpham ASP.NET 1.0 and 1.1 Basics 1 June 27th, 2005 09:16 PM
how to run files like in Windows teominator Beginning VB 6 4 January 23rd, 2005 11:47 AM



All times are GMT -4. The time now is 08:34 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.