0 leden en 1 gast bekijken dit topic.
Sub Voorbeeld() Dim bestand bestand = IsWorkBookOpen("C:\het te openenwerkboek.xlsx") If bestand = True Then MsgBox "Bestand is al open" Else 'dit kan je weglaten MsgBox "Bestand is niet open" ' dit kan je weglaten End IfEnd Sub
Sub cmd1_click()If Not IsWorkbookOpen("C:\Voorbeeldbestand.xlsm") Then Workbooks.Open ("C:\Voorbeeldbestand.xlsm")Else Msgbox(" Het bestand is al geopend")End IfEnd Sub
Private Function IsWorkBookOpen(ByVal FileName As String) As Boolean On Error Resume Next Dim wb As Workbook Set wb = Application.Workbooks(FileName) ' throws error 9 if non-existing Err.Clear On Error GoTo 0 IsWorkbookOpen = Not wb Is NothingEnd Function