Skip to content

Commit ea6129d

Browse files
committed
Check file exists before reading it
1 parent c2f2ff1 commit ea6129d

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

src/vbaDeveloper.xlam/NamedRanges.bas

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,17 @@ Public Sub importNamedRanges(wb As Workbook)
2222

2323
Dim fileName As String
2424
fileName = importDir & NAMED_RANGES_FILE_NAME
25-
2625
Dim fso As New Scripting.FileSystemObject
27-
Dim inStream As TextStream
28-
Set inStream = fso.OpenTextFile(fileName, ForReading, Create:=False)
29-
Dim line As String
30-
Do Until inStream.AtEndOfStream
31-
line = inStream.ReadLine
32-
importName wb, line
33-
Loop
26+
If fso.FileExists(fileName) Then
27+
Dim inStream As TextStream
28+
Set inStream = fso.OpenTextFile(fileName, ForReading, Create:=False)
29+
Dim line As String
30+
Do Until inStream.AtEndOfStream
31+
line = inStream.ReadLine
32+
importName wb, line
33+
Loop
34+
inStream.Close
35+
End If
3436
End Sub
3537

3638

src/vbaDeveloper.xlam/ThisWorkbook.sheet.cls

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ End Sub
1616
Private Sub Workbook_BeforeClose(Cancel As Boolean)
1717
Debug.Print "vbaDeveloper thisWorkbook_BeforeClose()"
1818
menu.deleteMenu
19-
customAction.beforeClose
20-
Set customAction = Nothing
19+
If Not customAction Is Nothing Then
20+
customAction.beforeClose
21+
Set customAction = Nothing
22+
End If
2123
Set listener = Nothing
2224
End Sub

0 commit comments

Comments
 (0)