bestand aanmaken als deze niet bestaat.

Status
Niet open voor verdere reacties.

tcgjohn

Gebruiker
Lid geworden
1 mrt 2007
Berichten
35
Hoe moet ik deze code aanpassen om een bestand NIET aan te maken als deze reeds bestaat? En vervolgens een MSG boxje te plaatsen die weergeeft dat het bestand reeds bestaat en dus niet kan worden aangemaakt?

Sub Maak7DagenWorkbook()


Sheets("Workbook").Select
Cells.Select
Selection.Copy

Workbooks.Add
Selection.PasteSpecial Paste:=xlPasteColumnWidths, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Range("H2:L2").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "=TODAY() + 7"
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Filename:=ActiveWorkbook.Path & "" & Format(Date + 7, "d mmmm") & ".xls", _
FileFormat:=xlNormal, Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, _
CreateBackup:=False
Application.DisplayAlerts = True
ActiveWindow.Close

Sheets("Dashboard").Select
Application.ScreenUpdating = True
End Sub

alvast bedankt.
John.
 
bestand

'Probeer dit:

Public Function FileExist(ByVal Filename As String) As Boolean
On Error GoTo ErrorHandler
FileExist = Len(Dir$(Filename)) > 0
Exit Function
ErrorHandler:
FileExist = False
End Function

'Gebruik:
If FileExist("Bestand") then
msgbox "Bestand bestaat"
End If

If NOT FileExist("Bestand") then
msgbox "Bestand bestaat NIET !"
End If
 
Bestand

'Of dit:

Bestand$ = App.Path & "\VB-Data\" & "Clienten.txt"
If Not FileExist(Bestand$) Then
Open Bestand$ For Output As #99
Print #99, ""
Close #99
End If
 
Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan