Moderatori: Anthony47, Flash30005
salvare il file con altro nome tramite macro
ed eventualmente eliminare il precedente se non occorre più
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
If Not IsDate(Cells(Rows.Count, "B").End(xlUp).Value) Then Exit Sub
Application.EnableEvents = False
Application.DisplayAlerts = False '!!! Vedi Testo
NewFName = Left(ThisWorkbook.FullName, Len(ThisWorkbook.FullName) - Len("28-07-2013.xls")) & _
Format(Cells(Rows.Count, "B").End(xlUp).Value, "dd-mm-yyyy") & ".xls"
ThisWorkbook.SaveAs Filename:=NewFName
Cancel = True
MsgBox ("Salvato file, nome corrente: " & vbCrLf & NewFName)
Application.EnableEvents = True
Application.DisplayAlerts = True
End Sub
NewFName = Left(ThisWorkbook.FullName, Len(ThisWorkbook.FullName) - Len("28-07-2013.xls")) & _
Format(Cells(Rows.Count, "B").End(xlUp).Value, "dd-mm-yyyy") & ".xls"
Sono assolutamene scettico sulla capacita' di una webquery di mettere sul foglio excel una data nel formato corretto.
.Columns("B:B").NumberFormat = "m/d/yyyy"
Devi partire da un file che è già nominato ...
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Dim sFolder As String
Dim sFilename As String
sFolder = ThisWorkbook.Path
sFilename = Left(ThisWorkbook.FullName, _
Len(ThisWorkbook.FullName) - _
Len("28-07-2013.xls")) & _
Format(Cells(Rows.Count, "B") _
.End(xlUp).Value, "dd-mm-yyyy")
On Error Resume Next
If Not IsDate(Cells(Rows.Count, "B") _
.End(xlUp).Value) Then Exit Sub
Application.EnableEvents = False
Application.DisplayAlerts = False
'FACCIAMO COINCIDERE LA DIRECTORY CON QUELLA STABILITA IN sFolder
'SE VI E' ERRORE SARA' CREATA LA CARTELLA
ChDir (sFolder)
'SE LA CARTELLA NON ESISTE USCIAMO DALLA ROUTINE
If Err.Number = 76 Then
Exit Sub
Else
With ThisWorkbook
'.SaveAs Filename:=(sFilename)
'OPPURE
.SaveAs (sPath & sFilename) '<<<<<<<
End With
Cancel = True
MsgBox ("Salvato file, nome corrente: " & vbCrLf & sFilename)
Application.EnableEvents = True
Application.DisplayAlerts = True
End If
End Sub
worksheets("Foglio1").range("B1").value=...
oppure
with worksheets("Foglio1")
.range("B1").value=...
end with
Infatti hai individuato, lavorando solo sul codice, un clamoroso baco di quanto ti ho proposto.nella tua macro non si fa riferimento al foglio che contiene le date
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
With Sheets("Foglio2") '<<<<
If Not IsDate(.Cells(Rows.Count, "B").End(xlUp).Value) Then Exit Sub
Application.EnableEvents = False
Application.DisplayAlerts = False '!!!
NewFName = Left(ThisWorkbook.FullName, Len(ThisWorkbook.FullName) - Len("28-07-2013.xls")) & _
Format(.Cells(Rows.Count, "B").End(xlUp).Value, "dd-mm-yyyy") & ".xls"
ThisWorkbook.SaveAs Filename:=NewFName
Cancel = True
MsgBox ("Salvato file, nome corrente: " & vbCrLf & NewFName)
Application.EnableEvents = True
Application.DisplayAlerts = True
End With
Saved = True
End Sub
ChDir (sFolder)
'SE LA CARTELLA NON ESISTE USCIAMO DALLA ROUTINE
If Err.Number = 76 Then
Exit Sub
Torna a Applicazioni Office Windows
Inserire dati filtrati da 2 file ad un terzo file Autore: Ricky0185 |
Forum: Applicazioni Office Windows Risposte: 14 |
Supporto per sviluppo macro VBA Ordinare per data Autore: Carletto Ribolla |
Forum: Applicazioni Office Windows Risposte: 3 |
Eliminare righe diverse dalla prima data del mese Autore: dipdip |
Forum: Applicazioni Office Windows Risposte: 4 |
Visitano il forum: Nessuno e 10 ospiti