Ciao Truster,
grazie per il consiglio, ho cercato di studiarmi gli oggetti Range e le proprietà Value ma il risultato è un gran mal di testa.
non riesco in alcun modo a salvare il file generato con il nome contenuto nella cella A30.
ho provato a fare delle prove inserendo vari codici tra altri codici senza nessun risultato,
la macro che sto cercando di correggere è questa:
Sub SaveAsXml()
Dim Fso As Object, Origine As Object, Destinazione As Object, Fo As Object, Fd As Object
Dim Tn, Nome As String, I As Long, sInput As String
' Dim Tn, NomeFileFe As String, I As Long, sInput As String
' NomeFileFe = Range("A30")
Application.DisplayAlerts = False
Tn = Split(ThisWorkbook.Name, ".")
For I = LBound(Tn) To UBound(Tn) - 1
Nome = Nome & Tn(I) & "."
' assegnando a Nome il contenuto della cella A30 & "."
' NomeFileFe = NomeFileFe & Tn(I) & "."
' Nome = NomeFileFe & Tn(I) & "."
Next I
' Dim Path As String ' PROVA
' Path = "E:\FattureFE\"
' fname = ThisWorkbook.Path & "\" & NomeFileFe & "xml" ' mi salva con il nome xml
' fname = ThisWorkbook.Path & "\" & Nome & "xml"
' ActiveWorkbook.SaveAs Filename:=Path & Filename & ".xlm", FileFormat:=xlNormal 'PROVA
fname = ThisWorkbook.Path & "\" & Nome & "xml"
ThisWorkbook.SaveAsXMLData Filename:=fname, Map:= _
ThisWorkbook.XmlMaps("FatturaElettronica_mapping")
Application.DisplayAlerts = True
Set Fso = CreateObject("Scripting.FileSystemObject")
Set Fo = Fso.GetFile(fname)
Set Origine = Fo.OpenAsTextStream(1, -2)
Fso.CreateTextFile ThisWorkbook.Path & "\Temp_" & Nome & "xml"
Set Fd = Fso.GetFile(ThisWorkbook.Path & "\Temp_" & Nome & "xml")
' Fso.CreateTextFile ThisWorkbook.Path & "\Temp_" & NomeFileFe & "xml"
' Set Fd = Fso.GetFile(ThisWorkbook.Path & "\Temp_" & NomeFileFe & "xml")
Set Destinazione = Fd.OpenAsTextStream(2, -2)
I = 0
With Origine
For I = 1 To 2
sInput = .readline
Next
sInput = "<?xml version=""" & "1.0" & """ encoding=" & """UTF-8""" & "?>"
Destinazione.writeline sInput
sInput = "<?xml-stylesheet type=""" & "text/xsl""" & " href=""" & "fatturapa_v1.0.xsl""" & "?>"
Destinazione.writeline sInput
sInput = "<p:FatturaElettronica versione=""" & "1.0"""
Destinazione.writeline sInput
sInput = "xmlns:ds=""" & "http://www.w3.org/2000/09/xmldsig#"""
Destinazione.writeline sInput
sInput = "xmlns:p=""" & "http://www.fatturapa.gov.it/sdi/fatturapa/v1.0"""
Destinazione.writeline sInput
sInput = "xmlns:xsi=""" & "http://www.w3.org/2001/XMLSchema-instance""" & ">"
Destinazione.writeline sInput
While Not .AtEndOfStream
sInput = .readline
If .AtEndOfStream Then Destinazione.writeline "</p:FatturaElettronica>" Else Destinazione.writeline sInput
Wend
End With
Origine.Close
Destinazione.Close
' NomeFileFe = Fo.Name
Nome = Fo.Name
Fo.Delete
' Fd.Name = NomeFileFe
Fd.Name = Nome
Set Fo = Nothing
Set Fd = Nothing
Set Origine = Nothing
Set Destinazione = Nothing
Set Fso = Nothing
End Sub
le prove le ho fatte precedere dal segno '
il codice così come è salva il file.xml nella stessa cartella del file che lo genera.
Se ti interessa vedere il file di esempio le trovi a questo link.
https://www.dropbox.com/s/2f6efa8wej...rWeb.xlsm?dl=0
Grazie della pazienza e scusate la mia ignoranza in materia.
Roberto