Una famiglia di software per fogli di calcolo Microsoft con strumenti per l'analisi, la creazione di grafici e la comunicazione dei dati.
Ciao Nicola,
Buongiorno a tutti, ciao Norman.
Nonostante avessi sostituito le righe che tu mi hai suggerito, il problema non si risolve nel file esportato in formato xlsx.
Ho preferito inviartelo sulla tua posta personale poiché contiene dati sensibili, parecchio codice vba e formule.
Questo è il codice che definitivo, con il tuo ultimo suggerimento:
Public Sub Copia_Foglio_Domanda()
Dim FileExtStr As String
Dim FileFormatNum As Long
Dim SourceWB As Workbook
Dim destWB As Workbook
Dim TempFilePath As String
Dim TempFileName As String
Dim i As Long
Dim oleObj As OLEObject
Const sPassword As String = "abc" '<<=== Modifica
With Application
.ScreenUpdating = False
.EnableEvents = False
End With
Set SourceWB = ActiveWorkbook
Sheets("Foglio1").Copy
With ActiveSheet
.Unprotect Password:=sPassword
For Each oleObj In .OLEObjects
If TypeName(oleObj.Object) = "CommandButton" Then
oleObj.Delete
End If
Next oleObj
.UsedRange.Value = .UsedRange.Value.UsedRange.Locked = True
.Protect Password:=sPassword
'.UsedRange.Locked = True remmate perchè devo esportare solo i dati e non le formule
'.Protect Password:=sPassword
End With
Set destWB = ActiveWorkbook
TempFilePath = SourceWB.Path & ""
TempFileName = Sheets("Foglio1").Range("B3").Value & " " & Sheets("Foglio1").Range("B5").Value & _
Sheets("Foglio1").Range("D3").Value & "_" & Format(Now, "dd-mmm-yy h-mm-ss")With destWB
Application.DisplayAlerts = False
.SaveAs TempFilePath & TempFileName & FileExtStr, _
FileFormat:=51Application.DisplayAlerts = True
' On Error Resume Next
' For i = 1 To 3
' .SendMail "", _
'""
'If Err.Number = 0 Then Exit For
' Next i
' On Error GoTo 0
.Close SaveChanges:=True
End WithCall Elimina_File
'Kill TempFilePath & TempFileName & ".xlsx"With Application
.ScreenUpdating = True
.EnableEvents = True
End With
End Sub
e l'errore è sempre lo stesso, vedi immagine del file xlsx creato:
Grazie per la tua immensa disponibilità
Ho ricevuto il tuo file e ho capito il problema,
Prova a sostituire la procedura Copia_Foglio_Domanda con la seguente versione:
'========>>
Public Sub Copia_Foglio_Domanda()
Dim FileExtStr As String
Dim FileFormatNum As Long
Dim SourceWB As Workbook
Dim destWB As Workbook
Dim TempFilePath As String
Dim TempFileName As String
Dim i As Long
Dim oleObj As OLEObject
Const sPassword As String = "abc" '<<=== Modifica
With Application
.ScreenUpdating = False
.EnableEvents = False
End With
Set SourceWB = ActiveWorkbook
With SourceWB.Sheets("Foglio1")
.UsedRange.Value = .UsedRange.Value
.Copy
End With
With ActiveSheet
.Unprotect Password:=sPassword
For Each oleObj In .OLEObjects
If TypeName(oleObj.Object) = "CommandButton" Then
oleObj.Delete
End If
Next oleObj
.UsedRange.Locked = True
.Protect Password:=sPassword
End With
Set destWB = ActiveWorkbook
TempFilePath = SourceWB.Path & ""
TempFileName = Sheets("Foglio1").Range("B3").Value & " " _
& Sheets("Foglio1").Range("B5").Value & _
Sheets("Foglio1").Range("D3").Value & "_" _
& Format(Now, "dd-mmm-yy h-mm-ss")
With destWB
Application.DisplayAlerts = False
.SaveAs TempFilePath & TempFileName & FileExtStr, _
FileFormat:=51
Application.DisplayAlerts = True
' On Error Resume Next
' For i = 1 To 3
' .SendMail "", _
'""
'If Err.Number = 0 Then Exit For
' Next i
' On Error GoTo 0
.Close SaveChanges:=True
End With
Call Elimina_File
'Kill TempFilePath & TempFileName & ".xlsx"
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
End Sub
'<<========
===
Regards,
Norman