prova questa macro che, partendo dal file excel prodoto con la macro precedente, ricostruisce i sei file TXT.
- Codice: Seleziona tutto
Option Explicit
Option Compare Text
Option Base 1
Public Dato_da_Scrivere As String, UR As Long, I As Long, I_App As Long, J As Integer, Appoggio0 As Integer, Appoggio1 As Integer, Appoggio2 As Integer, Appoggio3 As Integer
Sub Scrivi_TXT()
Dim Percorso As String, NomeFile As String, ElencoNomiFile()
ReDim ElencoNomiFile(6)
ElencoNomiFile(1) = "localvarsdescrCHECK.txt"
ElencoNomiFile(2) = "localvarsdescrCOMMAND.txt"
ElencoNomiFile(3) = "localvarsdescrCONTROL.txt"
ElencoNomiFile(4) = "localvarsdescrLOCAL.txt"
ElencoNomiFile(5) = "localvarsdescrSTATIC.txt"
ElencoNomiFile(6) = "localvarsdescrSTATUS.txt"
Percorso = "D:\TEMP\" ' <<------------- Inserire il nome del percorso in cui si trova il file EXCEL prodotto con l'altra MACRO
For J = 1 To 6
NomeFile = ElencoNomiFile(J)
Sheets(Mid(Left(NomeFile, Len(NomeFile) - 4), 15)).Select
UR = Range("C" & Rows.Count).End(xlUp).Row
On Error GoTo Fine
'....................................................................
' I nomi dei seguenti file puoi scriverli come preferisci.
' Io ho scelto di anteporre "NEW_" al nome preesistente.
' Vedi tu come fare !!!
Open Percorso & "NEW_" & NomeFile For Output As #1
'....................................................................
Scrivi_Righe
Close 1
Next J
MsgBox "Fine Elaborazione"
Application.DisplayAlerts = True
Exit Sub
Fine:
Close 1
MsgBox "Elaborazione INTERROTTA: " & " Errore n. " & Err & " - " & Err.Description & vbCrLf & vbCrLf & "Nome foglio: " & Mid(Left(NomeFile, Len(NomeFile) - 4), 15) & " - Indice Matrice: " & J
End Sub
Sub Scrivi_Righe()
For I = 5 To UR
Dato_da_Scrivere = Cells(I, 1) & ";"
Print #1, Dato_da_Scrivere
Dato_da_Scrivere = "!GLE ShortDescription: " & Chr(34) & Cells(I, 2) & Chr(34) & ";"
Print #1, Dato_da_Scrivere
I_App = I
Dato_da_Scrivere = "!GLE ValueDescription: " & Chr(34) & Cells(I, 3) & "|-|"
I = I + 1
Do While Cells(I, 1) = "" And I <= UR
Dato_da_Scrivere = Dato_da_Scrivere & Cells(I, 3) & "|-|"
I = I + 1
Loop
I = I - 1
Dato_da_Scrivere = Dato_da_Scrivere & Chr(34) & ";"
Print #1, Dato_da_Scrivere
Dato_da_Scrivere = "!GLE DefaultText: " & Chr(34) & Cells(I_App, 4) & Chr(34) & ";"
Print #1, Dato_da_Scrivere
Dato_da_Scrivere = "!GLE DefaultTextShort: " & Chr(34) & Cells(I_App, 5) & Chr(34) & ";"
Print #1, Dato_da_Scrivere
Dato_da_Scrivere = "!GLE LongDescription: " & Chr(34) & Cells(I_App, 6) & Chr(34) & ";"
Print #1, Dato_da_Scrivere
Print #1, ""
Next I
End Sub
Prova e ... sono QUI