I have this giant macro that I have built by piecing together a ton of different examples and changing pieces by trial and error. First here is a quick summary of what the code does:
1.) This spreadsheet can take up to 20 minutes to calculate upon opening and it needs to be sent out daily to my executive team, emailing it is not an option
2.) The VBA code, copies the important tabs in a values format to a temporary workbook, and then emails out the temporary workbook automatically.
I have tried everything but I don't know how to do a pain freeze on the temporary workbook I email out. What I would like is on the tab in the temporary workbook called "datavalues" I would like the pane to be frozen at cell I5.
What do I need to add to the code in order to do this? Also if anyone of you experts spot some clean up that would be great, like I said this is over a years worth of daily tinkering and cutting and pasting for me.
</hudsonsreporting@gmail.com>
1.) This spreadsheet can take up to 20 minutes to calculate upon opening and it needs to be sent out daily to my executive team, emailing it is not an option
2.) The VBA code, copies the important tabs in a values format to a temporary workbook, and then emails out the temporary workbook automatically.
I have tried everything but I don't know how to do a pain freeze on the temporary workbook I email out. What I would like is on the tab in the temporary workbook called "datavalues" I would like the pane to be frozen at cell I5.
What do I need to add to the code in order to do this? Also if anyone of you experts spot some clean up that would be great, like I said this is over a years worth of daily tinkering and cutting and pasting for me.
Code:
'This procedure will send the dashboard tab and a values pasted tab of the data tab
'to the emails listed on the email tab, the spreadsheet will be stripped of macros
'and sent as a *.xlsx file
Sub PasteValueMail()
'Working in 97-2007
Dim FileExtStr As String
Dim FileFormatNum As Long
Dim Sourcewb As Workbook
Dim Destwb As Workbook
Dim TempFilePath As String
Dim TempFileName As String
Dim iMsg As Object
Dim iConf As Object
Dim Flds As Variant
Dim sh As Worksheet
Dim WS As Worksheet
Dim WS1 As Worksheet
Dim ws2 As Worksheet
Dim ws3 As Worksheet
Dim ws4 As Worksheet
Dim ws5 As Worksheet
Dim ws6 As Worksheet
Dim ws7 As Worksheet
Dim ws8 As Worksheet
Dim x As Integer
With Application
.ScreenUpdating = False
.EnableEvents = False
.DisplayAlerts = False
End With
'Unprotect worksheets to be copied to destination workbook
For Each WS In ThisWorkbook.Worksheets
WS.Unprotect
Next WS
'Take a values only copy of "data", "Promo", and "ADP" tab
ThisWorkbook.Unprotect "xxxxxxx"
With ActiveWorkbook
Set WS1 = .Worksheets("Data")
Set ws2 = .Worksheets.Add(After:=WS1)
Set ws3 = .Worksheets.Add(After:=ws2)
Set ws4 = .Worksheets("ADP")
Set ws5 = .Worksheets("promo")
Set ws6 = .Worksheets.Add(After:=ws2)
Set ws7 = .Worksheets("Email")
Set ws8 = .Worksheets.Add(After:=ws6)
End With
WS1.Range("A1:AO500").Copy
ws2.Name = "DataValues"
With ws2.Range("A1")
.PasteSpecial Paste:=xlPasteValues
.PasteSpecial Paste:=xlPasteFormats
.PasteSpecial Paste:=xlPasteColumnWidths
End With
Application.CutCopyMode = False
ws4.Range("A1:K8000").Copy
ws3.Name = "ADPValues"
With ws3.Range("A1")
.PasteSpecial Paste:=xlPasteValues
.PasteSpecial Paste:=xlPasteFormats
.PasteSpecial Paste:=xlPasteColumnWidths
End With
Application.CutCopyMode = False
ws5.Range("A1:R400").Copy
ws6.Name = "PromoValues"
With ws6.Range("A1")
.PasteSpecial Paste:=xlPasteValues
.PasteSpecial Paste:=xlPasteFormats
.PasteSpecial Paste:=xlPasteColumnWidths
End With
Application.CutCopyMode = False
ws7.Range("A1:Z50").Copy
ws8.Name = "EmailValues"
With ws8.Range("A1")
.PasteSpecial Paste:=xlPasteValues
.PasteSpecial Paste:=xlPasteFormats
.PasteSpecial Paste:=xlPasteColumnWidths
End With
Application.CutCopyMode = False
Set Sourcewb = ActiveWorkbook
'Copy the ActiveSheet to a new workbook
'ActiveSheet.Copy
'Or if you want to copy more then one sheet use:
Sourcewb.Sheets(Array("Dashboard", "ADPValues", "DataValues", "PromoValues", "EmailValues")).Copy
ThisWorkbook.Sheets("DataValues").Delete
ThisWorkbook.Sheets("ADPValues").Delete
ThisWorkbook.Sheets("PromoValues").Delete
ThisWorkbook.Sheets("EmailValues").Delete
ThisWorkbook.Protect Password:="xxxxxxxxx", Structure:=True, Windows:=False
'Protection back on for worksheets copied over to destination workbook
For Each WS In ThisWorkbook.Worksheets
WS.Protect
Next WS
Set Destwb = ActiveWorkbook
'Select cell A1 on each worksheet of destination workbook
For x = Sheets.Count To 1 Step -1
Set WS = Worksheets(x)
WS.Activate
Application.Goto Reference:=WS.Range("A1"), Scroll:=True
Next
'Change destination workbook to .xlsx,
With Destwb
FileExtStr = ".xlsx": FileFormatNum = 51
End With
' 'Change all cells in Destwb to values if you want
For Each sh In Destwb.Worksheets
With sh.UsedRange
.Cells.Value = .Cells.Value
End With
Next sh
'Save the new workbook/Mail it/Delete it
TempFilePath = Environ$("temp") & "\"
TempFileName = Sheets("Dashboard").Range("C4").Value & " Dashboard - " & Format(Sheets("Dashboard").Range("C2").Value, "mmm dd, yyyy")
With Destwb
.SaveAs TempFilePath & TempFileName & FileExtStr, FileFormat:=FileFormatNum
.Close savechanges:=False
End With
Set iMsg = CreateObject("CDO.Message")
Set iConf = CreateObject("CDO.Configuration")
iConf.Load -1 ' CDO Source Defaults
Set Flds = iConf.Fields
With Flds
.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "xxxxxxxxxxx@xxxxxxxxxxx.com"
.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "xxxxxxxxxxx"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "xxxxxxxxxxx.xxxxxxxxxxx.com"
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = xxxxxxxxxxx
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = xxxxxxxxxxx
.Update
End With
With iMsg
Set .Configuration = iConf
.To = Sheets("Email").Range("B2").Value & ";" & Sheets("Email").Range("B3").Value & ";" & Sheets("Email").Range("B4").Value & ";" & Sheets("Email").Range("B5").Value & ";" & Sheets("Email").Range("B6").Value & ";" & Sheets("Email").Range("B7").Value & ";" & Sheets("Email").Range("B8").Value & ";" & Sheets("Email").Range("B9").Value & ";" & Sheets("Email").Range("B10").Value & ";" & Sheets("Email").Range("B11").Value & ";" & Sheets("Email").Range("B12").Value
.CC = ""
.BCC = ""
.ReplyTo = Sheets("Email").Range("B4").Value
.From = """Hudsons Reporting"" <xxxxxxxxxxx@xxxxxxxxxxx.com>"
.Subject = Sheets("Dashboard").Range("C4").Value & " Dashboard - " & Format(Sheets("Dashboard").Range("C2").Value, "mmm dd, yyyy")
.TextBody = "Attached is the " & Sheets("Dashboard").Range("C4").Value & " Dashboard run as at " & Format(Sheets("Dashboard").Range("C2").Value, "mmm dd, yyyy")
.AddAttachment TempFilePath & TempFileName & FileExtStr
.Send
End With
'Delete the file you have send
Kill TempFilePath & TempFileName & FileExtStr
ThisWorkbook.Sheets("Dashboard").Select
With Application
.ScreenUpdating = True
.EnableEvents = True
.DisplayAlerts = True
End With
End Sub
Last edited by a moderator: