Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 30th, 2007, 03:43 AM
Authorized User
 
Join Date: Mar 2007
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.




 
Old March 30th, 2007, 03:53 AM
Friend of Wrox
 
Join Date: Sep 2005
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
 
Old April 4th, 2007, 01:09 AM
Authorized User
 
Join Date: Mar 2007
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


 
Old April 4th, 2007, 01:16 AM
Friend of Wrox
 
Join Date: Sep 2005
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





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





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