File tree Expand file tree Collapse file tree 2 files changed +23
-2
lines changed
Expand file tree Collapse file tree 2 files changed +23
-2
lines changed Original file line number Diff line number Diff line change @@ -365,12 +365,33 @@ Private Sub setExportRange()
365365 ' be set to Nothing, which twigs the error-state check in
366366 ' setExportEnabled and setExportRangeText
367367
368+ Dim isSheetEmpty As Boolean
369+
370+ ' Detect if the sheet is *actually* completely empty
371+ ' .UsedRange returns Range($A$1) rather than Nothing, if
372+ ' sheet is completely empty
373+ With Selection.Parent
374+ If .UsedRange.Address = "$A$1" And IsEmpty(.UsedRange) Then
375+ isSheetEmpty = True
376+ Else
377+ isSheetEmpty = False
378+ End If
379+ End With
380+
368381 If Selection.Areas.Count <> 1 Then
369382 Set ExportRange = Nothing
370383 Else
384+ ' Handle if entire rows or columns (or both) are selected
371385 If Selection.Address = Selection.EntireRow.Address Or _
372- Selection.Address = Selection.EntireColumn.Address Then
373- Set ExportRange = Intersect(Selection, Selection.Parent.UsedRange)
386+ Selection.Address = Selection.EntireColumn.Address Then
387+ If isSheetEmpty Then
388+ ' There's definitely no content to be intersected with
389+ ' the selection! This copes with the above "$A$1" return
390+ ' from .UsedRange.
391+ Set ExportRange = Nothing
392+ Else
393+ Set ExportRange = Intersect(Selection, Selection.Parent.UsedRange)
394+ End If
374395 Else
375396 Set ExportRange = Selection
376397 End If
You can’t perform that action at this time.
0 commit comments