• 使用选择创建一个新的工作簿。

  • 在邮寄之前保存工作簿。

  • 发送后从硬盘中删除文件。

它将取消隐藏选择中隐藏的行和列。选择之外的所有空白单元格都被隐藏(请参见屏幕快照)

这样,选择始终位于工作表的顶部

Sub Mail_Selection()

Dim strDate As String

Dim Addr As String

Dim rng As Range

If ActiveWindow.SelectedSheets.Count > 1 Or Selection.Areas.Count > 1 Then Exit Sub

Application.ScreenUpdating = False

Addr = Selection.Address

ActiveSheet.Copy

ActiveSheet.Pictures.Delete

With Cells

.EntireColumn.Hidden = False

.EntireRow.Hidden = False

End With

Range(Addr).Select

Set rng = Selection

Application.GoTo rng, True

With rng.EntireColumn

.Hidden = True

rng(1).EntireRow.SpecialCells(xlVisible).EntireColumn.Clear

rng(1).EntireRow.SpecialCells(xlVisible).EntireColumn.Hidden = True

.Hidden = False

End With

With rng.EntireRow

.Hidden = True

rng(1).EntireColumn.SpecialCells(xlVisible).EntireRow.Clear

rng(1).EntireColumn.SpecialCells(xlVisible).EntireRow.Hidden = True

.Hidden = False

End With

Application.GoTo rng, True

rng.Cells(1).Select

strDate = Format(Date, "dd-mm-yy") & " " & Format(Time, "h-mm-ss")

ActiveWorkbook.SaveAs "Part of " & ThisWorkbook.Name _

& " " & strDate & ".xls"

ActiveWorkbook.SendMail "[email protected]", _

"This is the Subject line"

ActiveWorkbook.ChangeFileAccess xlReadOnly

Kill ActiveWorkbook.FullName

ActiveWorkbook.Close False

Application.ScreenUpdating = True

End Sub