Advertisement

08.08.2007 at 03:00PM PDT, ID: 22750783
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

7.0

Macro to get files froma directory

Asked by ark989 in Spreadsheet Software, Visual Basic Programming, Microsoft Excel Spreadsheet Software

Tags: , , , ,

I have a macro which scans all excel  files in a directory. but the path of the directory is in the VB code.
i would like to know if this can be changed. i . e . path should be in the excel sheet (easy for the user to change the path before running the macro).
the macro which i have(credit to jeverist @EE for the code)

Sub CombineFiles()
Dim wb_new As Workbook, ws As Worksheet, ws_o As Worksheet, ws_c As Worksheet, wb As Workbook, sh As Worksheet
Dim rng As Range, cel As Range, fld As String, fil As String, i As Long

With Application
    .DisplayAlerts = False
    .ScreenUpdating = False
    .EnableEvents = False
    .Calculation = xlCalculationManual
End With

fld = "C:\Documents and Settings\arkovvur\Desktop\week1"
fld = fld & Application.PathSeparator

Set wb_new = Workbooks.Add
If wb_new.Worksheets.Count < 2 Then wb_new.Worksheets.Add
For i = 1 To wb_new.Worksheets.Count
    Select Case i
    Case 1
        Set ws_o = wb_new.Worksheets(i)
        ws_o.Name = "Open"
    Case 2
        Set ws_c = wb_new.Worksheets(i)
        ws_c.Name = "Closed"
    Case Else
        wb_new.Worksheets(i).Delete
    End Select
Next i
       
fil = Dir(fld & "*.xls")
Do While (fil <> "")
    Set wb = Workbooks.Open(fld & fil)
    For Each sh In wb.Worksheets
        Select Case Trim(Left(LCase(sh.Name), 5))
        Case "open"
            Set ws = ws_o
        Case "close"
            Set ws = ws_c
        Case Else
            Set ws = Nothing
        End Select
       
        If Not ws Is Nothing Then
            If ws.UsedRange.Cells.Count = 1 Then
                sh.Rows(3).Copy Destination:=ws.Rows(1)
            End If
           
            Set rng = Range(sh.Cells(5, "A"), sh.Cells(sh.Rows.Count, "A").End(xlUp)).Resize(ColumnSize:=sh.UsedRange.Columns.Count)
           
            If Not rng Is Nothing Then
                With ws.Cells(ws.Rows.Count, "A").End(xlUp)
                    rng.Copy Destination:=.Offset(1)
                End With
            End If
        End If
    Next sh
   
    wb.Close SaveChanges:=False
   
    fil = Dir
Loop

For i = 1 To 2
    Select Case i
    Case 1
        Set ws = ws_o
    Case 2
        Set ws = ws_c
    End Select
   
    With ws
        For Each cel In Intersect(ws.UsedRange, ws.Columns("H")).Cells
            If Trim(cel) = "" Then cel = Date
        Next cel
       
        Union(.Columns("B"), .Columns("D:G")).Delete
       
        With .UsedRange.Columns(Application.CountA(.Rows(1))).Offset(0, 1)
            .FormulaR1C1 = "=RC[-1]-RC[-2]"
            .NumberFormat = "General"
            .Cells(1).Value = "Days Open"
        End With
       
        With .UsedRange.Columns(Application.CountA(.Rows(1))).Offset(0, 1)
            .FormulaR1C1 = "=ROUNDUP(RC[-1]/7,0)"
            .NumberFormat = "General"
            .Cells(1).Value = "Weeks Open"
        End With
       
        With .UsedRange
            .Columns.AutoFit
            .Sort Key1:=.Range("D2"), Order1:=xlDescending, Header:=xlGuess
        End With
    End With
Next i

With Application
    .DisplayAlerts = True
    .ScreenUpdating = True
    .EnableEvents = True
    .Calculation = xlCalculationAutomatic
End With

End Sub
Start Free Trial
[+][-]08.08.2007 at 03:24PM PDT, ID: 19658520

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Spreadsheet Software, Visual Basic Programming, Microsoft Excel Spreadsheet Software
Tags: excel, macro, directory, file, get
Sign Up Now!
Solution Provided By: jeverist
Participating Experts: 2
Solution Grade: A
 
 
[+][-]08.08.2007 at 03:30PM PDT, ID: 19658551

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08.08.2007 at 03:35PM PDT, ID: 19658583

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08.08.2007 at 03:36PM PDT, ID: 19658587

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08.08.2007 at 04:46PM PDT, ID: 19658882

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08.08.2007 at 04:47PM PDT, ID: 19658887

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08.09.2007 at 12:30AM PDT, ID: 19660290

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20081112-EE-VQP-42 / EE_QW_2_20070628