Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle idiosyncrasy of .UsedRange on empty sheet #26

Merged
merged 1 commit into from
Feb 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions src/UFExporter.frm
Original file line number Diff line number Diff line change
Expand Up @@ -365,12 +365,33 @@ Private Sub setExportRange()
' be set to Nothing, which twigs the error-state check in
' setExportEnabled and setExportRangeText

Dim isSheetEmpty As Boolean

' Detect if the sheet is *actually* completely empty
' .UsedRange returns Range($A$1) rather than Nothing, if
' sheet is completely empty
With Selection.Parent
If .UsedRange.Address = "$A$1" And IsEmpty(.UsedRange) Then
isSheetEmpty = True
Else
isSheetEmpty = False
End If
End With

If Selection.Areas.Count <> 1 Then
Set ExportRange = Nothing
Else
' Handle if entire rows or columns (or both) are selected
If Selection.Address = Selection.EntireRow.Address Or _
Selection.Address = Selection.EntireColumn.Address Then
Set ExportRange = Intersect(Selection, Selection.Parent.UsedRange)
Selection.Address = Selection.EntireColumn.Address Then
If isSheetEmpty Then
' There's definitely no content to be intersected with
' the selection! This copes with the above "$A$1" return
' from .UsedRange.
Set ExportRange = Nothing
Else
Set ExportRange = Intersect(Selection, Selection.Parent.UsedRange)
End If
Else
Set ExportRange = Selection
End If
Expand Down
Binary file modified src/UFExporter.frx
Binary file not shown.