Ciao Sandro,
sto testando e sembra andar bene con il seguente codice
Private Sub cmdFile_Click()
Dim lngSlashPos As Long
Dim fullPath As String
fullPath = cmdFileDialog
If Len(fullPath & vbNullString) = 0 Then Exit Sub
lngSlashPos = InStrRev(fullPath, "")
Me.txtPath = Mid$(fullPath, 1, lngSlashPos)
Me.txtFile = justFileName(fullPath)
Dim iRisposta As Integer
iRisposta = MsgBox("Vuoi modificare il nome del file ???", vbYesNoCancel)
Select Case iRisposta 'impostiamo il Select Case con riferimento al messaggio restituito dalla variabile iRisposta
Case vbYes 'se risponderemo "Si" :
Me.txtNuovoNomeFile = vbNullString ' aggiunta
Me.txtNuovoNomeFile.SetFocus
Me.txtNuovoNomeFile.BackColor = vbRed
Case vbNo 'se sceglieremo "No":
Me.txtNuovoNomeFile = Me.txtFile
End Select
bool = True
End Sub
e con
Private Sub txtNuovoNomeFile_BeforeUpdate(Cancel As Integer)
If bool Then
If FileExists(Me.txtPath & Me.txtNuovoNomeFile) Then
VBA.MsgBox Me.txtPath & Me.txtNuovoNomeFile & vbNewLine & _
" esiste già assegna un altro nome!", vbCritical, "Warning"
Cancel = True
Else
Name Me.txtPath & Me.txtFile As Me.txtPath & Me.txtNuovoNomeFile
Me.txtNuovoNomeFile.BackColor = vbWhite
VBA.MsgBox "Ho rinominato :" & vbNewLine & _
Me.txtPath & Me.txtFile & vbNewLine & _
" così:" & vbNewLine & _
Me.txtPath & Me.txtNuovoNomeFile, vbInformation
bool = False
End If
End If
End Sub
Ho modificato il comando copia files sostituendo il txt.File con txt.NUovoNomeFIle
Private Sub cmdCopyFiles3_Click()
Const myPath As String = "C:\Users\Nebbia\Desktop" ' <----- personalizza il path!!
If Not folderExists(myPath) Then MkDir myPath
If Not FileExists(Me.txtNuovoNomeFile) Then VBA.MsgBox "il file non esiste", vbCritical, "warning": Exit Sub
Dim strFile As String
Dim i As Integer
Dim strFileName As String
strFile = justFileName(Me.txtNuovoNomeFile)
If Not folderExists(myPath & Me.txtCategoria) Then
MkDir myPath & Me.txtCategoria
End If
If Not folderExists(myPath & Me.txtCategoria & "" & Me.txtSottocategoria) Then
MkDir myPath & Me.txtCategoria & "" & Me.txtSottocategoria
End If
strFileName = myPath & Me.txtCategoria & "" & Me.txtSottocategoria & "" & strFile
i = 1
Do While Len(Dir(strFileName)) > 0
strFileName = "copia di (" & i & ") " & strFile
i = i + 1
strFileName = myPath & Me.txtCategoria & "" & Me.txtSottocategoria & "" & strFileName
Loop
strFile = strFileName
FileCopy Me.txtNuovoNomeFile, strFile
If FileExists(strFile) Then VBA.MsgBox "file copiato con successo", vbInformation, "Info"
Me.txtNuovoPercorso = myPath & Me.txtCategoria & "" & Me.txtSottocategoria & ""
Sembra andar bene, a parte l'estensione :-))) e, forse, a mio avviso, non influente, sarebe opportuno far uscire un messaggio se il file che viene copiato è già presente nella cartella/sottocartella
Grazie ancora... che fatica...