Hide UserForm on copy

SharonCas

New Member
Joined
May 25, 2019
Messages
2
Hello,

I currently have a UserForm showing when opening a workbook. A copy of this workbook is sent to Outlook with a Macro. The problem I am having is that the UserForm is showing when the copy is made thus requiring the user to close the form before the email is displayed. I don't know where to put the Hide form or me.Unload in the Send to outlook Macro. Any assistance would be greatly appreciated.

Sub MailWorkbookOutlook()


Application.ScreenUpdating = False


If ActiveSheet.Range("N26,W26") = "" Then
MsgBox ("Must enter RENTAL EQUIP & TRAFFIC CONTROL before sending")
Exit Sub
Else
End If




Dim rng As Range
Dim wb1 As Workbook
Dim wb2 As Workbook
Dim FileExtStr As String
Dim OutApp As Object
Dim OutMail As Object
Dim DatePicked As String
Dim PcName As String
Dim ws As Worksheet
Dim strbody As String

DatePicked = ActiveSheet.Range("E23").Value
PcName = ActiveSheet.Range("T13").Value


Set wb1 = ActiveWorkbook



Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)


On Error Resume Next
With OutMail
.To = "Dailies@bluecomm.com"
.CC = ""
.BCC = ""
.Subject = DatePicked & " - " & PcName
.Body = "CREW MEMBERS ON SITE:" & vbCrLf & "EQUIPMENT ON SITE:" & vbCrLf & vbCrLf & "DESCRIPTION OF TASKS PERFORMED:"
.Attachments.Add wb2.FullName
' In place of the .Send, you can use ".Display" to display the mail.
.Display
End With
On Error GoTo 0

Set OutMail = Nothing
Set OutApp = Nothing

Application.ScreenUpdating = True
End Sub
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Hello,

I currently have a UserForm showing when opening a workbook.

do you want this userform in the emailed copy or just the sheets in the workbook?
you could have a macro that loops through and copies sheets to a new workbook w/o the userform and then sends that new workbook.
or create a save file with a different name and have another if statement that says if its the copies' name do not show userform, etc.
those are a couple workarounds i could think of.
 
Upvote 0
I don't have the time today to integrate this into your code but copying the workbook to a new workbook with a predictable name:

Code:
Sub createWB()
Dim wb1 As Workbook
Set wb1 = ThisWorkbook
Dim wb2 As Workbook
Set wbT2 = Workbooks.Add

For Each Sheet In wb1.Sheets
    Sheet.Copy after:=wb2.Sheets(wb2.Sheets.Count)
Next
End Sub

If you haven't worked something out tomorrow or If anyone else wants to help:
I'll be back tomorrow to help
 
Upvote 0
After going over everything what you probably need to do is enter an "if not" statement on the userform code that says

If not (activeworkbook's name is equal to wb2) then me.show
else exit sub

So what that will do is if the active workbook has the same name as the copy of the workbook it will exit the sub without showing the userform.
You didn't post all of your codes so i can't write it out exactly, but you seem to have a pretty good grasp of VBA
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,286
Members
452,631
Latest member
a_potato

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