| | Post: 55 | Registrato il: 19/01/2017
| Città: MILANO | Età: 56 | Utente Junior | 2010 | | OFFLINE | |
|
28/11/2017 10:00 | |
Buongiorno a tutti, ogni tanto chiedo il vostro aiuto, utilizziamo tanto i file di testo, e ogni tanto li dobbiamo reimportare, e fin qui nessun problema excel offre tante possibilità, dovendo automatizzare questa procedura, mi sono affidato al registratore di macro, e devo dire che il codice creato funziona molto bene, il problema che non sono riuscito a risolvere sta nel fatto che la macro registrata contiene posizione e nome del file di testo cosa che invece cambia da pc a pc. Quello che mi occorrerebbe è una modifica all'inizio della macro dove al posto del nome e posizione si apra la finestra di esplora risorse dove poter selezionare un file di testo con nome e posizioni differenti (i file di testo sono strutturati tutti allo stesso modo ecco perche la macro). allego la macro copiata in un file di testo. Grazie anticipatamente. |
|
| | Post: 4.022 | Registrato il: 13/03/2012
| Città: LIVORNO | Età: 78 | Utente Master | 2010 | | OFFLINE | |
|
28/11/2017 12:16 | |
Sub importadatitxt()
FName = Application.GetOpenFilename("Text Files (*.txt), *.txt")
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;" & FName, Destination:=Range("$A$2"))
.Name = "prova"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 850
.TextFileStartRow = 1
.TextFileParseType = xlFixedWidth
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
.TextFileFixedColumnWidths = Array(38, 106, 4, 60, 10, 4, 72, 1, 16)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
End Sub
----------
Win 10 - Excel 2010
allega un file di esempio, guadagnerai tempo tu e lo farai risparmiare a chi ti aiuta |
| | Post: 55 | Registrato il: 19/01/2017
| Città: MILANO | Età: 56 | Utente Junior | 2010 | | OFFLINE | |
|
28/11/2017 12:49 | |
Grazie infinite funziona perfettamente. |
|
|