Greetings!
First off, a big thank you to everyone one here. I have been lurking here for the last week and have "stolen" help from you guys and its all been great!
second, i hope i am not re-posting a question. I wasn't really finding anything for my search terms, so i apologize in case this is a re-post.
I have a work order template that i made, that with a click of a button, creates a new workbook with a incremented file name, imports a module into the workbook, emails notification to someone that the work order has been created, and prints out the work order.
The module that i imported contains a basic print macro, and a macro to send a notification to the creator of the work order that the status of the work order has changed. When i run either of these macros from the generated workbook, they launch the "master" workbook in order to run.
My goal is to make the new workbook independent from the master workbook.
The code i use to generate the file is:
and one of my macros in the created workbook is:
I made sure all my Dims were unique as i assumed it was looking for previous Dims but that hasn't changed how these macros operate.
Thanks for the help in advance
First off, a big thank you to everyone one here. I have been lurking here for the last week and have "stolen" help from you guys and its all been great!
second, i hope i am not re-posting a question. I wasn't really finding anything for my search terms, so i apologize in case this is a re-post.
I have a work order template that i made, that with a click of a button, creates a new workbook with a incremented file name, imports a module into the workbook, emails notification to someone that the work order has been created, and prints out the work order.
The module that i imported contains a basic print macro, and a macro to send a notification to the creator of the work order that the status of the work order has changed. When i run either of these macros from the generated workbook, they launch the "master" workbook in order to run.
My goal is to make the new workbook independent from the master workbook.
The code i use to generate the file is:
Code:
Sub SavePrintSend()
Dim NewFN As Variant
Dim OutApp As Object
Dim OutMail As Object
Dim strbody As String
Dim FileLocation As String
Dim NewFN2 As Variant
Dim NewFN3 As String
Dim CodeLocation As String
Dim DateCreate As String
'insert date into cell
DateCreate = Format(Date, "Long Date")
Range("E6").Value = DateCreate
' copy invoice to a new workbook
Sheets().Copy
'get file location of workbook to save to and name new workbook
NewFN2 = ThisWorkbook.Path & "\WO" & Range("E5").Value & ".xlsm"
NewFN3 = ThisWorkbook.Path & "\WO" & Range("E5").Value
ActiveWorkbook.SaveAs NewFN2, FileFormat:=xlOpenXMLWorkbookMacroEnabled
'copy VBA Module 2 for print and update buttons
CodeLocation = ThisWorkbook.Path & "code.txt"
ThisWorkbook.VBProject.VBComponents("Module2").Export CodeLocation
ActiveWorkbook.VBProject.VBComponents.Import CodeLocation
ActiveWorkbook.Save
'send to default printer
ActiveWorkbook.PrintOut
'email attachment, decomment below
'Application.Dialogs(xlDialogSendMail).Show
'email notification
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
strbody = "Hi there" & vbNewLine & vbNewLine & _
"A work order has been submitted to you." & vbNewLine & _
"The File is located at: " & NewFN2 & vbNewLine
On Error Resume Next
With OutMail
.To = ""
.CC = ""
.BCC = ""
.Subject = "Word order " & Range("E5").Value
.Body = strbody
.Display
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
' close new workbook and save and clear main workbook
ActiveWorkbook.Close
NextWorkorder
End Sub
and one of my macros in the created workbook is:
Code:
Sub SendUpdate() Dim NewFN4 As Variant
Dim strbody As String
Dim ReturnEmail As String
Dim Status As String
Dim FN As String
Status = Range("E8").Text
ReturnEmail = Range("L3").Text
NewFN4 = ThisWorkbook.Path
FN = ThisWorkbook.Name
'email notification
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
strbody = "Hi there" & vbNewLine & vbNewLine & _
"Your Work order " & Range("E5").Value & " has been updated" & vbNewLine & _
"The File is located at: " & NewFN4 & FN & vbNewLine & _
"The status has been changed to: " & Status
On Error Resume Next
With OutMail
.To = ReturnEmail
.CC = ""
.BCC = ""
.Subject = "Word order " & Range("E5").Value
.Body = strbody
.Display
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
End Sub
I made sure all my Dims were unique as i assumed it was looking for previous Dims but that hasn't changed how these macros operate.
Thanks for the help in advance