Improvement in my code (basic) to import files in excell VBA

2

Good evening.

I've been working on various spreadsheets with vba code for importing files, and after that, working on their numbers is with macro or formulas.

I'd like to get hints on improving this code, reducing rows, whatever. Any tips are welcome!

Thank you.

Sub AtualizarRelatorioGeral()
    Application.Calculation = xlCalculationManual
    Application.ScreenUpdating = False
    Application.EnableEvents = False
    Application.DisplayAlerts = False
    SaveChanges = False

    Dim Arquivo(18) As String

    Arquivo(1) = "zpp03ontem"
    Arquivo(2) = "vl10a"
    Arquivo(3) = "mb51consumomensal"
    Arquivo(4) = "mb51repassegerado"
    Arquivo(5) = "mb52peixerev"
    Arquivo(6) = "mb52peixepro"
    Arquivo(7) = "mb52exp"
    Arquivo(8) = "mb52repassesaldo"
    Arquivo(9) = "zsd17"
    Arquivo(10) = "zsd25fat"
    Arquivo(11) = "zsd25dev"
    Arquivo(12) = "mc.9estoquecd"
    Arquivo(13) = "mc.9consumo"
    Arquivo(14) = "mc.9centro"
    Arquivo(15) = "mc.9cdhipet"
    Arquivo(16) = "mc.9valor"
    Arquivo(17) = "zpp25"
    Arquivo(18) = "mc.9produto"

    For i = 1 To 18
        Sheets(Arquivo(i)).Visible = True
    Next i

    Set WBgeral = ActiveWorkbook

    'IMPORTAR ARQUIVOS
    For i = 1 To 18
        WBgeral.Activate
        Sheets(Arquivo(i)).Activate
        Cells.Select
        Selection.Clear
        Workbooks.OpenXML ("C:\macrosm\prerelatoriolucimara\" & Arquivo(i) & ".xls")
        Range("A1").Select
        Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
        Selection.Copy
        WBgeral.Activate
        Sheets(Arquivo(i)).Activate
        ActiveSheet.Paste
        Workbooks(Arquivo(i)).Close SaveChanges:=False
    Next i
    'IMPORTAR ARQUIVOS

    Sheets("Principal").Activate

    For i = 1 To 18
        'Sheets(Arquivo(i)).Visible = False
    Next i

    Cells(4, 16).Value = Date
    Application.Calculation = xlCalculationAutomatic
    Application.ScreenUpdating = True
    Application.EnableEvents = True
    Application.DisplayAlerts = True
    SaveChanges = True
End Sub
    
asked by anonymous 21.07.2018 / 00:54

0 answers