kmgingee
asked on
Hidden rows showing up in my email attachment
Hi Everyone:
Sorry if this is a really stupid question,but here goes:
I want to send a worksheet in the body of the mail,in the worksheet I have hidden cells:I unhide them but they still show up in the body of the email I send,Can some please show me how I unhide them in my macro? my code is pretty simple:
Sub Send_Range()
ActiveWorkbook.EnvelopeVis ible = True
' Set the optional introduction field thats adds
' some header text to the email body. It also sets
' the To and Subject lines. Finally the message
' is sent.
With ActiveSheet.MailEnvelope
.Introduction = "This is a sample worksheet."
.Item.To = "E-Mail_Address_Here"
.Item.Subject = "My subject"
.Item.Send
End With
End Sub
if it helps any: my hidden cells are from column F : column H,but i want the values in column I to be displayed.
if this is not doable my other (much disliked) option is have the the activesheet saved on the desktop and then the user sends it as an attachment.i really really dont want to do this
Sub MailSheet()
Dim shtName As String
shtName = ActiveSheet.Name
ActiveSheet.Copy
ActiveWorkbook.SaveAs FileName:=Application.GetS aveAsFilen ame("Copy of " & shtName, "Microsoft Excel File, *.xls")
Application.DisplayAlerts = False
Application.Dialogs(xlDial ogSendMail ).Show
With ActiveWorkbook
.ChangeFileAccess xlReadOnly
Kill .FullName
.Close False
End With
Application.DisplayAlerts = True
End Sub
so my request is either:
1)i am able to remove the hidden cells from the email body OR
2)send the activesheet as an attachment without saving on the users PC
Can someone please guide me?
Regards
Arun
Sorry if this is a really stupid question,but here goes:
I want to send a worksheet in the body of the mail,in the worksheet I have hidden cells:I unhide them but they still show up in the body of the email I send,Can some please show me how I unhide them in my macro? my code is pretty simple:
Sub Send_Range()
ActiveWorkbook.EnvelopeVis
' Set the optional introduction field thats adds
' some header text to the email body. It also sets
' the To and Subject lines. Finally the message
' is sent.
With ActiveSheet.MailEnvelope
.Introduction = "This is a sample worksheet."
.Item.To = "E-Mail_Address_Here"
.Item.Subject = "My subject"
.Item.Send
End With
End Sub
if it helps any: my hidden cells are from column F : column H,but i want the values in column I to be displayed.
if this is not doable my other (much disliked) option is have the the activesheet saved on the desktop and then the user sends it as an attachment.i really really dont want to do this
Sub MailSheet()
Dim shtName As String
shtName = ActiveSheet.Name
ActiveSheet.Copy
ActiveWorkbook.SaveAs FileName:=Application.GetS
Application.DisplayAlerts = False
Application.Dialogs(xlDial
With ActiveWorkbook
.ChangeFileAccess xlReadOnly
Kill .FullName
.Close False
End With
Application.DisplayAlerts = True
End Sub
so my request is either:
1)i am able to remove the hidden cells from the email body OR
2)send the activesheet as an attachment without saving on the users PC
Can someone please guide me?
Regards
Arun
ASKER
thanks kevin,but i get this error when i run your code:
Run-time error '1004'
Application-defined or object-defined error
Thanks
Arun
Run-time error '1004'
Application-defined or object-defined error
Thanks
Arun
What line?
Kevin
Kevin
ASKER
I Get the error in this line:
Run-time error '1004'
Cannot enter a null value as an item or field name in a pivot table report
it is coming on this line of your code:
Application.DisplayAlerts = False
I have attached the file for your reference
2009-Vacation-Tracking-Schedule.xls
Run-time error '1004'
Cannot enter a null value as an item or field name in a pivot table report
it is coming on this line of your code:
Application.DisplayAlerts = False
I have attached the file for your reference
2009-Vacation-Tracking-Schedule.xls
Fixed:
Sub read()
Dim SourceWorksheet As Worksheet
Dim Column As Long
Dim Calculation As Long
Application.ScreenUpdating = False
Calculation = Application.Calculation
Application.Calculation = xlCalculationManual
ActiveWorkbook.EnvelopeVis ible = True
' Set the optional introduction field thats adds
' some header text to the email body. It also sets
' the To and Subject lines. Finally the message
' is sent.
Application.DisplayAlerts = False
ThisWorkbook.ActiveSheet.C opy After:=ThisWorkbook.Active Sheet
Set SourceWorksheet = ActiveSheet
SourceWorksheet.UsedRange. Copy
SourceWorksheet.UsedRange. PasteSpeci al xlPasteValues
With SourceWorksheet.UsedRange
Column = .Column + .Columns.Count - 1
Do
If .Columns(Column).ColumnWid th = 0 Then
.Columns(Column).ColumnWid th = .Columns(Column + 1).ColumnWidth
.Columns(Column).Delete
End If
Column = Column - 1
Loop While Column >= .Column
End With
With SourceWorksheet.MailEnvelo pe
.Introduction = "This is a sample worksheet."
.Item.To = "E-Mail_Address_Here"
.Item.Subject = "My subject"
.Item.Send
End With
SourceWorksheet.Delete
Application.DisplayAlerts = True
Application.ScreenUpdating = True
Application.Calculation = Calculation
End Sub
Kevin
Sub read()
Dim SourceWorksheet As Worksheet
Dim Column As Long
Dim Calculation As Long
Application.ScreenUpdating
Calculation = Application.Calculation
Application.Calculation = xlCalculationManual
ActiveWorkbook.EnvelopeVis
' Set the optional introduction field thats adds
' some header text to the email body. It also sets
' the To and Subject lines. Finally the message
' is sent.
Application.DisplayAlerts = False
ThisWorkbook.ActiveSheet.C
Set SourceWorksheet = ActiveSheet
SourceWorksheet.UsedRange.
SourceWorksheet.UsedRange.
With SourceWorksheet.UsedRange
Column = .Column + .Columns.Count - 1
Do
If .Columns(Column).ColumnWid
.Columns(Column).ColumnWid
.Columns(Column).Delete
End If
Column = Column - 1
Loop While Column >= .Column
End With
With SourceWorksheet.MailEnvelo
.Introduction = "This is a sample worksheet."
.Item.To = "E-Mail_Address_Here"
.Item.Subject = "My subject"
.Item.Send
End With
SourceWorksheet.Delete
Application.DisplayAlerts = True
Application.ScreenUpdating
Application.Calculation = Calculation
End Sub
Kevin
ASKER
Thanks kevin,but unfortunately I still seem to be seeing the hidden cells showing up in the body of my mail:
I have attached a screenshot if it helps.
If this is not doable,i dont mind sending this activeworksheet as a excel attachment ( but it has to be automatic-no saving on the users PC)
any suggestions u might have?
untitled.JPG
I have attached a screenshot if it helps.
If this is not doable,i dont mind sending this activeworksheet as a excel attachment ( but it has to be automatic-no saving on the users PC)
any suggestions u might have?
untitled.JPG
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
WOAH,it worked! - AWESOME!!
thank you soo very much!!!!
u the man :)
thank you soo very much!!!!
u the man :)
Sub Send_Range()
Dim SourceWorksheet As Worksheet
Dim ColumnWidth As Double
Dim Column As Long
ActiveWorkbook.EnvelopeVis
' Set the optional introduction field thats adds
' some header text to the email body. It also sets
' the To and Subject lines. Finally the message
' is sent.
Application.DisplayAlerts = False
ThisWorkbook.ActiveSheet.C
Set SourceWorksheet = ActiveSheet
SourceWorksheet.UsedRange.
With SourceWorksheet.UsedRange
For Column = .Column To .Column + .Columns.Count - 1
If .Columns(Column).Hidden Then
ColumnWidth = .Columns(Column).Offset(0,
.Columns(Column).Delete
.Columns(Column).ColumnWid
End If
Next Column
End With
With SourceWorksheet.MailEnvelo
.Introduction = "This is a sample worksheet."
.Item.To = "E-Mail_Address_Here"
.Item.Subject = "My subject"
.Item.Send
End With
SourceWorksheet.Delete
Application.DisplayAlerts = True
End Sub
Kevin