martedì 9 luglio 2013

leggi ecofee metel

Attribute VB_Name = "leggi_ecofee_metel"

'

Option Explicit

'

' vba - Excel

' Legge ed importa un file di testo con il tracciato record

' Ecofee RAEE Metel

'

'

Sub leggiEcoFeeMetel()

'

Dim percorso

'

ChDir ("\\Caem02\listini")

percorso = Application.GetOpenFilename("Tutti i file (*.*), *.*")

If percorso = False Then

Exit Sub

End If

'

Sheets.Add

'

With ActiveSheet.QueryTables.Add(Connection:= _

"TEXT;" & percorso, Destination:= _

Range("A1"))

.Name = "ECOFEEMETEL"

.FieldNames = True

.RowNumbers = False

.FillAdjacentFormulas = False

.PreserveFormatting = True

.RefreshOnFileOpen = False

.RefreshStyle = xlInsertDeleteCells

.SavePassword = False

.SaveData = True

.AdjustColumnWidth = True

.RefreshPeriod = 0

.TextFilePromptOnRefresh = False

.TextFilePlatform = xlWindows

.TextFileStartRow = 1

.TextFileParseType = xlFixedWidth

.TextFileTextQualifier = xlTextQualifierDoubleQuote

.TextFileConsecutiveDelimiter = False

.TextFileTabDelimiter = True

.TextFileSemicolonDelimiter = False

.TextFileCommaDelimiter = False

.TextFileSpaceDelimiter = False

.TextFileColumnDataTypes = Array(2, 2, 2, 1, 2, 2, 2, 1, 1, 1, 2, 2, 2, 2)

.TextFileFixedColumnWidths = Array(3, 16, 20, 9, 30, 30, 70, 5, 8, 7, 3, 70, 29)

.Refresh BackgroundQuery:=False

End With

' testata

Dim foglio

Set foglio = Sheets(ActiveSheet.Name)

foglio.Cells(1, 1) = "Marchio"

foglio.Cells(1, 2) = "Codice articolo"

foglio.Cells(1, 3) = "Tipo tassa"

foglio.Cells(1, 4) = "Peso netto"

foglio.Cells(1, 5) = "Consorzio"

foglio.Cells(1, 6) = "Codice Fee"

foglio.Cells(1, 7) = "Descrizione Fee"

foglio.Cells(1, 8) = "Quantità Fee"

foglio.Cells(1, 9) = "Importo singolo Fee"

foglio.Cells(1, 10) = "Percentuale Fee"

foglio.Cells(1, 11) = "Soggetto a IVA o esenzione"

foglio.Cells(1, 12) = "Categoria merceologica"

foglio.Cells(1, 13) = "Filler"

' ' dividi

Dim quanterighe, contarighe, prezzonetto, nprezzonetto, divisore, importofee, nimportofee

Dim percentualefee, npercentualefee

quanterighe = ActiveSheet.UsedRange.Rows.Count

For contarighe = 1 To quanterighe

prezzonetto = ActiveSheet.Cells(contarighe, 4)

importofee = ActiveSheet.Cells(contarighe, 9)

percentualefee = ActiveSheet.Cells(contarighe, 10)

'

divisore = 1000

If IsNull(prezzonetto) = False And IsNumeric(prezzonetto) = True Then

nprezzonetto = prezzonetto / divisore

ActiveSheet.Cells(contarighe, 4) = nprezzonetto

End If

'

divisore = 10000

If IsNull(importofee) = False And IsNumeric(importofee) = True Then

nimportofee = importofee / divisore

ActiveSheet.Cells(contarighe, 9) = nimportofee

End If

'

divisore = 10000

If IsNull(percentualefee) = False And IsNumeric(percentualefee) = True Then

npercentualefee = percentualefee / divisore

ActiveSheet.Cells(contarighe, 10) = npercentualefee

End If

'

Next

'

Columns("D:D").Select

Selection.NumberFormat = "#,##0.000"

Columns("I:I").Select

Selection.NumberFormat = "#,##0.0000"

Columns("J:J").Select

' Selection.NumberFormat = "0.0000%"

'

Cells.Select

Cells.EntireColumn.AutoFit

Range("A2").Select

Range("A2").Activate

'

End Sub

Nessun commento:

Posta un commento