Excel仅显示userform,从不显示工作簿

时间:2017-11-15 07:53:28

标签: excel vba userform commandbutton

我目前有一个工作簿,它在打开时隐藏,我的用户窗体显示。我有一个按钮,在将其存储在工作簿上后发送电子邮件。当我按下发送它取消隐藏工作簿。我怎么能阻止这种情况发生。我还有一个组合框,显示了一个项目列表。我仍在努力研究如何根据选择动态显示标签和文本框。

Private Sub Workbook_Open()
Application.Visible = False
voneServiceRequest.Show
End Sub


Private Sub CommandButton2_Click()
'Copy Data Into Worksheet'
Worksheets("Order").Range("A1").Value = TextBox1.Value
Worksheets("Order").Range("A3").Value = TextBox2.Value
Worksheets("Order").Range("B4").Value = TextBox3.Value
Worksheets("Order").Range("B5").Value = SiteList.Text
Worksheets("Order").Range("B6").Value = TextBox4.Value
Worksheets("Order").Range("B7").Value = TextBox5.Value
Worksheets("Order").Range("B8").Value = TextBox6.Value
Worksheets("Order").Range("A10").Value = TextBox7.Value
Worksheets("Order").Range("B11").Value = RequestList.Text
Worksheets("Order").Range("A13").Value = TextBox8.Value
End Sub

Sub CommandButton3_Click()
    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 OutApp As Object
    Dim OutMail As Object

    With Application
        .ScreenUpdating = False
        .EnableEvents = False
    End With

    Set Sourcewb = ActiveWorkbook

    'Copy the ActiveSheet to a new workbook
    ActiveSheet.Copy
    Set Destwb = ActiveWorkbook

    'Determine the Excel version and file extension/format
    With Destwb
        If Val(Application.Version) < 12 Then
            'You use Excel 97-2003
            FileExtStr = ".xls": FileFormatNum = -4143
        Else
            'You use Excel 2007-2013
            Select Case Sourcewb.FileFormat
            Case 51: FileExtStr = ".xlsx": FileFormatNum = 51
            Case 52:
                If .HasVBProject Then
                    FileExtStr = ".xlsm": FileFormatNum = 52
                Else
                    FileExtStr = ".xlsx": FileFormatNum = 51
                End If
            Case 56: FileExtStr = ".xls": FileFormatNum = 56
            Case Else: FileExtStr = ".xlsb": FileFormatNum = 50
            End Select
        End If
    End With

    'Save the new workbook/Mail it/Delete it
    TempFilePath = Environ$("temp") & "\"
    TempFileName = ActiveSheet.Name & " " & Format(Now, "dd-mmm-yy")

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

    With Destwb
        .SaveAs TempFilePath & TempFileName & FileExtStr, FileFormat:=FileFormatNum
        On Error Resume Next
        With OutMail
            .to = "muhammad.qahar@vodafone.com"
            .CC = ""
            .BCC = ""
            .Subject = "RFS ORDER FORM [Insert Ref Here]"
            .BodyFormat = olFormatHTML
            .Body = "Hi, Please find attached the order form"




            .Attachments.Add Destwb.FullName

            .Display   ' .Send or use .Display
        End With
        On Error GoTo 0
        .Close savechanges:=False
    End With

    'Delete the file you have send
    Kill TempFilePath & TempFileName & FileExtStr

    Set OutMail = Nothing
    Set OutApp = Nothing

    With Application
        .ScreenUpdating = False
        .EnableEvents = True
    End With

End Sub



Private Sub CommandButton4_Click()
Worksheets("Order").Range("B4:B8").ClearContents
Worksheets("Order").Range("B11").ClearContents
End Sub

Sub UserForm_Initialize()

'Lock Labels on Worksheet'


'Add site list upon opening form'

With SiteList
    .AddItem "Birmingham"
    .AddItem "Bristol"
    .AddItem "Cardiff"
    .AddItem "Chelmsford"
    .AddItem "Edinburgh"
    .AddItem "Fenchurch Street"
    .AddItem "Glasgow"
    .AddItem "Guernsey"
    .AddItem "Halifax"
    .AddItem "Homeworker"
    .AddItem "Horsham"
    .AddItem "Ipswich"
    .AddItem "Jersey"
    .AddItem "Leeds"
    .AddItem "Leicester"
    .AddItem "Lennox Wood"
    .AddItem "Liverpool"
    .AddItem "Manchester"
    .AddItem "Peterborough"
    .AddItem "Redhill"
    .AddItem "Sunderland"
    .AddItem "Madrid"
End With

'Add list of requests upon opening form'

With RequestList
    .AddItem "Add Phone To VONE C", 0
    .AddItem "Add FMC", 1
    .AddItem "Add Voicemail", 2
    .AddItem "Create New Pickup Group", 3
    .AddItem "Create New Hunt Group", 4
    .AddItem "Dialling Permissions (Class of Service)", 5
    .AddItem "MMR", 6
    .AddItem "Name Change", 7
    .AddItem "New User", 8
    .AddItem "Pick Up Group Changes i.e Add/Remove User", 9
    .AddItem "Hunt Group Changes i.e. Add/Remove User", 10
    .AddItem "Remove Phone From VONE C", 11
    .AddItem "Remove User From VONE C", 12
    .AddItem "Remove FMC Capability", 13
    .AddItem "Remove Voicemail Capability", 14
End With

'Hide information required'

RequestList.Style = fmStyleDropDownList
frAddPhone.Visible = False

End Sub

Private Sub CommandButton1_Click()
Windows("RFS User Form Mock.xlsm").Visible = True
End Sub

Private Sub LegendDefinition_Change()
'Locks box from being edited by users'

LegendDefinition.Locked = True

End Sub

0 个答案:

没有答案