Macro to aufit Columns in Named range before attaching to Ouitlookq

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,601
Office Version
  1. 2021
Platform
  1. Windows
I have the folowing code to attach a named range in a sheet. The column width is perfect. Howver when the sheet is attached the column width in some columns is not wide enough and displays ###


Kindly test & amend code so that when the named range for the sheet is attached, the columns width fitts the size of the coluns


Code:
 Sub EmailRange()

Dim wb As Workbook, Path As String, Ztext As String, Zsubject As String

Ztext = [bodytext]                              'read in text from named cell
Zsubject = [SubjectText]

Set wb = ThisWorkbook: Path = "C:\My Documents"
With Workbooks.Add
    wb.Sheets("Sales Data").Range("EMLSales").Copy
    With ActiveSheet
        .Range("A1").PasteSpecial xlPasteValues
        .Columns.AutoFit
        .Name = "Sales Report"
    End With
    .SaveAs Path & "\" & "Sales Report" & ".xlsx"
    .Close True
End With
    With CreateObject("Outlook.Application").CreateItem(0)
    .display
        .To = Join(Application.Transpose(Sheets("Email Sales").Range("Z1:Z4").Value), ";")
        .CC = Join(Application.Transpose(Sheets("Email Sales").Range("AA1:AA12").Value), ";")
        .Subject = Zsubject
        .Body = Ztext
        
     .Attachments.Add Path & "\" & "Sales Report" & ".xlsx"
    '.Send
End With
Kill Path & "\" & "Sales Report" & ".xlsx"
End Sub
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.

Forum statistics

Threads
1,224,605
Messages
6,179,860
Members
452,948
Latest member
UsmanAli786

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