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 August 25th, 2011, 01:48 PM
Authorized User
 
Join Date: Aug 2011
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to open files one by one in an order??

Hi,

I've been trying to work on a macro to open files in a particular order. For eg :

RFC-1.xls
RFC-2.xls
RFC-3.xls
RFC-4.xls
RFC-5.xls

Also another condition is I need to open only those excel files that start with "RFC". Can anyone pls help? - Thanks

Justin
 
Old August 26th, 2011, 02:56 AM
Friend of Wrox
 
Join Date: Sep 2005
Posts: 812
Thanks: 1
Thanked 53 Times in 49 Posts
Default

Hi

The following hint can help you:

Code:
Sub FilterFiles()
Dim sPath As String
Dim sFile As String
Dim sDir As String
Dim oLB As Workbook
Dim i1 As Long
Dim iMax As Long
 
sPath = "C:\Users\Om\Downloads\"
sDir = FileSystem.Dir(sPath & "RFC*.xls", vbNormal)
Do Until LenB(sDir) = 0
   Debug.Print sDir
    Set oLB = Workbooks.Open(sPath & sDir)
    
    ' -- Do Something
    If oLB.Saved = False Then oLB.Save
    oLB.Close False
    sDir = Dir$
Loop

End Sub
Cheers
Shasur
__________________
C# Code Snippets (http://www.dotnetdud.blogspot.com)

VBA Tips & Tricks (http://www.vbadud.blogspot.com)
 
Old August 26th, 2011, 09:17 AM
Authorized User
 
Join Date: Aug 2011
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Smile

Thanks Shashur.. That really helped... It's working just perfect!

Thanks again!
Justin
 
Old August 27th, 2011, 04:52 AM
Friend of Wrox
 
Join Date: Sep 2005
Posts: 812
Thanks: 1
Thanked 53 Times in 49 Posts
Default

Hi Justin

Glad to hear that

Cheers
Shasur
__________________
C# Code Snippets (http://www.dotnetdud.blogspot.com)

VBA Tips & Tricks (http://www.vbadud.blogspot.com)





Similar Threads
Thread Thread Starter Forum Replies Last Post
Pdf files doesn't open Ciupaz BOOK: Beginning C# 3.0 : An Introduction to Object Oriented Programming ISBN: 978-0-470-26129-3 2 September 11th, 2008 04:36 PM
Error on trying to open passworded files southernsun Beginning VB 6 2 March 25th, 2008 10:32 AM
Backup Log Files out of order khautinh SQL Server 2000 2 March 16th, 2007 01:41 AM
Auto Open Files Hugh Excel VBA 1 December 17th, 2003 01:00 PM





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