Results 1 to 9 of 9

Macro on multiple files and save in other fileformat

Threaded View

  1. #1
    Registered User
    Join Date
    03-08-2010
    Location
    Sweden
    MS-Off Ver
    MS Office 365 Mac and Windows
    Posts
    94

    Macro on multiple files and save in other fileformat

    Hello!
    I have this macro that I want to use on all files in a folder (*.csv). It can be up 100 files at the most and it is hard work doing manually. Is there a way to put this macro to be able to run on all files in a folder and at the best be saved as an excelfile (as I want to keep the formatting).

    Original files are *csv files...

    
    Sub JusteraRutter()
    '
    ' Makro1 Makro
    '
    
    '
        Columns("A:A").Select
        Selection.TextToColumns Destination:=Range("A1"), DataType:=xlDelimited, _
            TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
            Semicolon:=True, Comma:=False, Space:=False, Other:=False, FieldInfo _
            :=Array(Array(1, 1), Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 1), _
            Array(7, 1), Array(8, 1), Array(9, 1)), TrailingMinusNumbers:=True
        Range("D1").Select
        Selection.End(xlDown).Select
        Selection.Copy
        ActiveCell.Offset(1, -1).Activate
        ActiveSheet.Paste
        
        Range("D3").Select
        Range(Selection, Selection.End(xlDown)).Select
        Application.CutCopyMode = False
        Selection.ClearContents
        Range("C2").Select
        Selection.End(xlDown).Select
        Selection.Cut
        ActiveCell.Offset(-1, 1).Activate
        ActiveSheet.Paste
        
        Columns("H:H").Select
        Selection.Insert Shift:=xlToRight
        Selection.Insert Shift:=xlToRight
        Selection.Insert Shift:=xlToRight
        Selection.Insert Shift:=xlToRight
        Selection.Insert Shift:=xlToRight
        Selection.Insert Shift:=xlToRight
        
        Range("H2").Select
        ActiveCell.FormulaR1C1 = _
            "=IF(ISERROR(FIND(""PLD"",RC[-2],1)),"""",MID(RC[-2],FIND(""PLD"",RC[-2],1)+4,5)*1)"
        Range("I2").Select
        ActiveCell.FormulaR1C1 = _
            "=IF(ISERROR(FIND(""PL Ej Direkt"",RC[-3],1)),"""",MID(RC[-3],FIND(""PL Ej Direkt"",RC[-3],1)+13,5)*1)"
        Range("J2").Select
        ActiveCell.FormulaR1C1 = _
            "=IF(ISERROR(FIND(""FBX"",RC[-4],1)),"""",MID(RC[-4],FIND(""FBX"",RC[-4],1)+4,5)*1)"
        Range("K2").Select
        ActiveCell.FormulaR1C1 = _
            "=IF(ISERROR(FIND(""FFH Gång"",RC[-5],1)),"""",MID(RC[-5],FIND(""FFH Gång"",RC[-5],1)+9,5)*1)"
            Range("L2").Select
        ActiveCell.FormulaR1C1 = _
            "=IF(ISERROR(FIND(""FFH Hiss"",RC[-6],1)),"""",MID(RC[-6],FIND(""FFH Hiss"",RC[-6],1)+9,5)*1)"
            Range("M2").Select
        ActiveCell.FormulaR1C1 = _
            "=IF(ISERROR(FIND(""Fritidshushåll"",RC[-7],1)),"""",MID(RC[-7],FIND(""Fritidshushåll"",RC[-7],1)+15,5)*1)"
            
        Range("H2:M2").Select
        Selection.Copy
        Range("G2").Select
        Selection.End(xlDown).Select
        ActiveCell.Offset(0, 1).Activate
        Range(Selection, Selection.End(xlUp)).Select
        ActiveSheet.Paste
            
        Range("H1").Select
        ActiveCell.FormulaR1C1 = " PLD "
        Range("I1").Select
        ActiveCell.FormulaR1C1 = " PL-Ej Dir "
        Range("J1").Select
        ActiveCell.FormulaR1C1 = " FBX "
        Range("K1").Select
        ActiveCell.FormulaR1C1 = " FFH-G "
        Range("L1").Select
        ActiveCell.FormulaR1C1 = " FFH-H "
        Range("M1").Select
        ActiveCell.FormulaR1C1 = " SPL "
        Range("H2").Select
        
        Rows("1:1").Select
        Selection.Insert Shift:=xlDow
    
        Range("A2").Select
        Range(Selection, Selection.End(xlToRight)).Select
        Range(Selection, Selection.End(xlUp)).Select
        Selection.Font.Bold = True
        With Selection.Interior
            .ColorIndex = 15
            .Pattern = xlSolid
        End With
        
        Range("D1:E1").Select
        With Selection
            .HorizontalAlignment = xlRight
            .VerticalAlignment = xlBottom
            .WrapText = False
            .Orientation = 0
            .AddIndent = False
            .IndentLevel = 0
            .ShrinkToFit = False
            .ReadingOrder = xlContext
            .MergeCells = False
        End With
        Range("E1").Select
        ActiveCell.FormulaR1C1 = "Antal stopp med:"
        
        Range("H1").Select
            ActiveCell.FormulaR1C1 = "=COUNT(R[2]C:R[500]C)"
        Range("I1").Select
        ActiveCell.FormulaR1C1 = "=COUNT(R[2]C:R[500]C)"
        Range("J1").Select
        ActiveCell.FormulaR1C1 = "=COUNT(R[2]C:R[500]C)"
        Range("K1").Select
        ActiveCell.FormulaR1C1 = "=COUNT(R[2]C:R[500]C)"
        Range("L1").Select
        ActiveCell.FormulaR1C1 = "=COUNT(R[2]C:R[500]C)"
        Range("M1").Select
        ActiveCell.FormulaR1C1 = "=COUNT(R[2]C:R[500]C)"
        Range("N1").Select
            
        Cells.Select
        Cells.EntireColumn.AutoFit
        
        Range("A:A,C:E,G:G,H:N").Select
        Range("H1").Activate
        With Selection
            .HorizontalAlignment = xlCenter
            .VerticalAlignment = xlBottom
            .WrapText = False
            .Orientation = 0
            .AddIndent = False
            .IndentLevel = 0
            .ShrinkToFit = False
            .ReadingOrder = xlContext
            .MergeCells = False
        End With
        
        Columns("G:M").Select
        Selection.Copy
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
        Application.CutCopyMode = False
        Columns("F:F").Select
        Selection.Cut
        Columns("P:P").Select
        ActiveSheet.Paste
        Columns("F:F").Select
        Selection.Delete Shift:=xlToLeft
        Range("A2").Select
        
        'Range("A2").Select
        With ActiveSheet.PageSetup
            .PrintTitleRows = "$1:$2"
            .PrintTitleColumns = ""
        End With
        ActiveSheet.PageSetup.PrintArea = "$A:$M"
        With ActiveSheet.PageSetup
            .LeftHeader = ""
            .CenterHeader = ""
            .RightHeader = ""
            .LeftFooter = ""
            .CenterFooter = ""
            .RightFooter = ""
            .LeftMargin = Application.InchesToPoints(0.393700787401575)
            .RightMargin = Application.InchesToPoints(0.393700787401575)
            .TopMargin = Application.InchesToPoints(0.590551181102362)
            .BottomMargin = Application.InchesToPoints(0.393700787401575)
            .HeaderMargin = Application.InchesToPoints(0.511811023622047)
            .FooterMargin = Application.InchesToPoints(0.511811023622047)
            .PrintHeadings = False
            .PrintGridlines = True
            .PrintComments = xlPrintNoComments
            .PrintQuality = 600
            .CenterHorizontally = False
            .CenterVertically = False
            .Orientation = xlLandscape
            .Draft = False
            .PaperSize = xlPaperA4
            .FirstPageNumber = xlAutomatic
            .Order = xlDownThenOver
            .BlackAndWhite = False
            .Zoom = 100
            .PrintErrors = xlPrintErrorsDisplayed
        End With
    End Sub
    Last edited by soreno; 03-10-2010 at 01:04 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1