henkvanerp
Gebruiker
- Lid geworden
- 13 jun 2007
- Berichten
- 21
Onderstaande macro slaat het automatisch bestand op als bestandsnaam (cel A2) in het pad (cel A1)niet bestaat.
Als het bestand bestaat wordt deze vervangen. Prima zo. Echter:
Als het bestand al bestaat en geopend is dan wil ik dat deze wordt gesloten zonder op te slaan en dat de macro dan doorloopt en dus alsnog het bestand gaat opslaan.
Application.DisplayAlerts = False
Dim Path As String
Dim filename As String
Path = Range("A1") ‘Dir staat in cel A1
filename = Range("A2") ‘Bestandsnaam staat in cel A2
ActiveWorkbook.SaveAs filename:=Path & filename & ".xlsx", FileFormat:=51
Application.DisplayAlerts = True
Wie weet raad? Mijn dank.
Als het bestand bestaat wordt deze vervangen. Prima zo. Echter:
Als het bestand al bestaat en geopend is dan wil ik dat deze wordt gesloten zonder op te slaan en dat de macro dan doorloopt en dus alsnog het bestand gaat opslaan.
Application.DisplayAlerts = False
Dim Path As String
Dim filename As String
Path = Range("A1") ‘Dir staat in cel A1
filename = Range("A2") ‘Bestandsnaam staat in cel A2
ActiveWorkbook.SaveAs filename:=Path & filename & ".xlsx", FileFormat:=51
Application.DisplayAlerts = True
Wie weet raad? Mijn dank.