would like to include don't show gridline in send email vba

pcorpz

Active Member
Joined
Oct 29, 2004
Messages
324
How can I disable gridline in the create temp file to send to outlook vba?

Sub Send_Email()
Dim Email_Subject, Email_Send_From, Email_Body As String, i As Integer
Dim Mail_Object, nameList As String, o As Variant, ws As Worksheet, ws1 As Worksheet
With Application
.ScreenUpdating = False
.EnableEvents = False
End With
Set ws = Worksheets("SalesRep")
ans = MsgBox("Are you sure you want to send email's to all individuals in list ??", vbYesNo)
If ans = vbNo Then Exit Sub
For i = 2 To 10
Worksheets(ws.Range("A" & i).Value).Copy
With Worksheets(ws.Range("A" & i).Value).UsedRange
.Cells.Copy
.Cells.PasteSpecial xlPasteFormats
.Cells.PasteSpecial xlPasteValuesAndNumberFormats
End With
Application.CutCopyMode = False
TempFilePath = Environ$("temp") & ""
TempFileName = ws.Range("A" & i).Value & " " & Format(Now, "dd-mmm-yy")
FileExtStr = ".xlsx"
FileFormatNum = 51
With ActiveWorkbook
.SaveAs TempFilePath & TempFileName & FileExtStr, FileFormat:=FileFormatNum
End With
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Hello pcorpz,

I have added indents to your code. As you can see what you posted is incomplete. Rather than turn Gridlines on and off and creating text files to attach to the email, why not add the Range into the body of the email?

Code:
Sub Send_Email()


    Dim Email_Subject, Email_Send_From, Email_Body As String, i As Integer
    Dim Mail_Object, nameList As String, o As Variant, ws As Worksheet, ws1 As Worksheet


        With Application
            .ScreenUpdating = False
            .EnableEvents = False
        End With
        
        Set ws = Worksheets("SalesRep")
        
        ans = MsgBox("Are you sure you want to send email's to all individuals in list ??", vbYesNo)
        If ans = vbNo Then Exit Sub     ' Note: Because you have Disabled events, you need to Enab;le events before exiting
        
        For i = 2 To 10
            Worksheets(ws.Range("A" & i).Value).Copy
            
            With Worksheets(ws.Range("A" & i).Value).UsedRange
                .Cells.Copy
                .Cells.PasteSpecial xlPasteFormats
                .Cells.PasteSpecial xlPasteValuesAndNumberFormats
            End With
            
            Application.CutCopyMode = False
            
            TempFilePath = Environ$("temp") & ""
            TempFileName = ws.Range("A" & i).Value & " " & Format(Now, "dd-mmm-yy")
            
            FileExtStr = ".xlsx"
            FileFormatNum = 51
            
            With ActiveWorkbook
                .SaveAs TempFilePath & TempFileName & FileExtStr, FileFormat:=FileFormatNum
           ' Missing End With
        ' Missing Next i
        
End With


Here is a link that might help Mail Range/Selection in the body of mail
 
Last edited:
Upvote 0
Hello pcorpz,

I have added indents to your code. As you can see what you posted is incomplete. Rather than turn Gridlines on and off and creating text files to attach to the email, why not add the Range into the body of the email?

Code:
Sub Send_Email()


    Dim Email_Subject, Email_Send_From, Email_Body As String, i As Integer
    Dim Mail_Object, nameList As String, o As Variant, ws As Worksheet, ws1 As Worksheet


        With Application
            .ScreenUpdating = False
            .EnableEvents = False
        End With
        
        Set ws = Worksheets("SalesRep")
        
        ans = MsgBox("Are you sure you want to send email's to all individuals in list ??", vbYesNo)
        If ans = vbNo Then Exit Sub     ' Note: Because you have Disabled events, you need to Enab;le events before exiting
        
        For i = 2 To 10
            Worksheets(ws.Range("A" & i).Value).Copy
            
            With Worksheets(ws.Range("A" & i).Value).UsedRange
                .Cells.Copy
                .Cells.PasteSpecial xlPasteFormats
                .Cells.PasteSpecial xlPasteValuesAndNumberFormats
            End With
            
            Application.CutCopyMode = False
            
            TempFilePath = Environ$("temp") & ""
            TempFileName = ws.Range("A" & i).Value & " " & Format(Now, "dd-mmm-yy")
            
            FileExtStr = ".xlsx"
            FileFormatNum = 51
            
            With ActiveWorkbook
                .SaveAs TempFilePath & TempFileName & FileExtStr, FileFormat:=FileFormatNum
           ' Missing End With
        ' Missing Next i
        
End With


Here is a link that might help Mail Range/Selection in the body of mail

Hi Leith! Thanks for your reply. Sorry, I didn't include the rest of the code with the assumption that it's not needed for this particular post (to add the don't show gridline code). Also to answer your question, I prefer to have it copied as an attachment than the body of email. Easier for the users to navigate and update. =)
 
Upvote 0
Hello pcorpz,

You can turn off Gridlines like this...

Code:
ActiveWindow.DisplayGridlines = False

To restore them...

Code:
ActiveWindow.DisplayGridlines = True
 
Upvote 0
Hello pcorpz,

You can turn off Gridlines like this...

Code:
ActiveWindow.DisplayGridlines = False

To restore them...

Code:
ActiveWindow.DisplayGridlines = True

Thanks Leith.. I realize this is the code to turn it off but my challenge is incorporating it to the send email vba? Where would I add this line?..
 
Upvote 0
Hello pcorpz,

Turn them off at the start of the code and restore them before you exit the routine. Here is an example...

Code:
Sub Send_Email()


    Dim Email_Subject, Email_Send_From, Email_Body As String, i As Integer
    Dim Mail_Object, nameList As String, o As Variant, ws As Worksheet, ws1 As Worksheet


        ActiveWindow.DisplayGridlines = False
        
        With Application
            .ScreenUpdating = False
            .EnableEvents = False
        End With
        
        Set ws = Worksheets("SalesRep")
        
        ans = MsgBox("Are you sure you want to send email's to all individuals in list ??", vbYesNo)
        If ans = vbNo Then Exit Sub     ' Note: Because you have Disabled events, you need to Enab;le events before exiting
        
        For i = 2 To 10
            Worksheets(ws.Range("A" & i).Value).Copy
            
            With Worksheets(ws.Range("A" & i).Value).UsedRange
                .Cells.Copy
                .Cells.PasteSpecial xlPasteFormats
                .Cells.PasteSpecial xlPasteValuesAndNumberFormats
            End With
            
            Application.CutCopyMode = False
            
            TempFilePath = Environ$("temp") & ""
            TempFileName = ws.Range("A" & i).Value & " " & Format(Now, "dd-mmm-yy")
            
            FileExtStr = ".xlsx"
            FileFormatNum = 51
            
            With ActiveWorkbook
                .SaveAs TempFilePath & TempFileName & FileExtStr, FileFormat:=FileFormatNum
           ' Missing End With
        ' Missing Next i
        
        ActiveWindow.DisplayGridlines = True
        
End With
 
Upvote 0
Hello pcorpz,

Turn them off at the start of the code and restore them before you exit the routine. Here is an example...

Code:
Sub Send_Email()


    Dim Email_Subject, Email_Send_From, Email_Body As String, i As Integer
    Dim Mail_Object, nameList As String, o As Variant, ws As Worksheet, ws1 As Worksheet


        ActiveWindow.DisplayGridlines = False
        
        With Application
            .ScreenUpdating = False
            .EnableEvents = False
        End With
        
        Set ws = Worksheets("SalesRep")
        
        ans = MsgBox("Are you sure you want to send email's to all individuals in list ??", vbYesNo)
        If ans = vbNo Then Exit Sub     ' Note: Because you have Disabled events, you need to Enab;le events before exiting
        
        For i = 2 To 10
            Worksheets(ws.Range("A" & i).Value).Copy
            
            With Worksheets(ws.Range("A" & i).Value).UsedRange
                .Cells.Copy
                .Cells.PasteSpecial xlPasteFormats
                .Cells.PasteSpecial xlPasteValuesAndNumberFormats
            End With
            
            Application.CutCopyMode = False
            
            TempFilePath = Environ$("temp") & ""
            TempFileName = ws.Range("A" & i).Value & " " & Format(Now, "dd-mmm-yy")
            
            FileExtStr = ".xlsx"
            FileFormatNum = 51
            
            With ActiveWorkbook
                .SaveAs TempFilePath & TempFileName & FileExtStr, FileFormat:=FileFormatNum
           ' Missing End With
        ' Missing Next i
        
        ActiveWindow.DisplayGridlines = True
        
End With

Thank you Leith! This works. =D I was unsure where to include it and the couple attempts I inserted it, I got the run-time error. Still trying to understand vba and its concepts. Thanks so much!
 
Upvote 0
Hello pcorpz,

You're welcome. Glad you got it working.
 
Upvote 0

Forum statistics

Threads
1,214,553
Messages
6,120,182
Members
448,948
Latest member
spamiki

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top