Combining Two sets of Code - Save as a particular file name based on info in file & email to set person

Chelsea0270516

New Member
Joined
Oct 15, 2015
Messages
32
Hello!

I haven't written any code myself yet. But I have used recording macros & lots of google searches to get a few time savers for some of the work I do.

I have one set of code that works to delete my autolook ups (basically it copy & pastes special so no vlookups are left), then it saves the doc to a particular location, with a name that is specific to the data I put in the document. It also saves without macros enabled & closes the document.

My second set of code was written by someone on here (I saw it this morning actually!). It does something (which I cut cut out because I didn't need it) & then prompts outlook to email a specific person.

I am wondering - could someone help me figure out how to combine the two sets of code to make a different set that does the following:


  1. Automatically saves the document with the following format
    1. [Contents of C14]&"-WHSE130-Display Order CMM-"&Today()
    2. Today in MMDDYY format
    3. Example: 2211-WHSE130-Display Order CMM-042216
  2. It needs to be saved in a particular location.
  3. It needs to be saved as a basic workbook (no macros enabled)
  4. It needs to email me once it is saved with the item attached & the name of the document as the subject of the email.

I am using an existing form & can't add in any lines to the excel sheet to help create the name which is an area I am running into trouble with. Before I just had a hidden tab that compiled all the information I needed to create the correct name for the document. Now I need to figure out how to combine these things in VBA which is one of my big issues.

functioning delete auto lookups
[TABLE="width: 500"]
<tbody>[TR]
[TD]Sub DeleteAutoLookUps()
'
' DeleteAutoLookUps Macro
'
' Keyboard Shortcut: Ctrl+Shift+Q
'
Range("A1:M73").Select
Selection.Copy
ActiveWindow.SmallScroll Down:=-33
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
ActiveWindow.SmallScroll Down:=-15
Sheets("coding").Select
ActiveWindow.SelectedSheets.Visible = False
Sheets("Vendors").Select
ActiveWindow.SelectedSheets.Visible = False
Sheets("Paste Here").Select
ActiveWindow.SelectedSheets.Visible = False
Range("Q11").Select

'Save as function per stack overflow


Application.ScreenUpdating = False


'Exit if U2 is empty


If ActiveSheet.Range("U2").Value = vbNullString Then Exit Sub


ThisFile = ActiveSheet.Range("U2").Value


ActiveWorkbook.SaveAs "L:\data\Marketing\Z Shared Outside Files\Retail Store Displays\Chelsea\Waiting to be placed\" & ThisFile, FileFormat:=xlOpenXMLWorkbook
Application.ScreenUpdating = True
ActiveWorkbook.Close
End Sub
[/TD]
[/TR]
</tbody>[/TABLE]


email Code/what I have so far - red part is wrong but I don't know how to make it right. Light blue I changed but I am not sure the change is right.
[TABLE="width: 500"]
<tbody>[TR]
[TD]Sub EMAIL()


Dim OAPPS As Object
Dim OMAIL As Object
Dim LWORKBOOK As Workbook
Dim LFILENAME As String


Application.ScreenUpdating = False


ActiveSheet.Copy
Set LWORKBOOK = ActiveWorkbook


LFILENAME = AND (ActiveSheet.Range("C14")),("-WHSE130-Display Order CMM-"),(ActiveSheet.Range("O4")),("ActiveSheet.Range("C14"))


On Error Resume Next


Kill LFILENAME
On Error GoTo 0


LWORKBOOK.SaveAs Filename:=LFILENAME


Set OAPP = CreateObject("OUTLOOK.APPLICATION")
Set OMAIL = OAPP.CREATEITEM(0)


With OMAIL
.To = "chelsea@abcdef.com"
.Subject = LWORKBOOK.FullName
.ATTACHMENTS.Add LWORKBOOK.FullName
.DISPLAY
End With


LWORKBOOK.ChangeFileAccess Mode:=xlOpenXMLWorkbook
Kill LWORKBOOK.FullName
LWORKBOOK.Close SAVECHANGES:=False


Application.ScreenUpdating = True
Set OMAIL = Nothing
Set OAPP = Nothing


End Sub
[/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.

Forum statistics

Threads
1,223,214
Messages
6,170,771
Members
452,353
Latest member
strainu

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