首页 > 解决方案 > VBA代码周末日期名称和特定文件夹并自动保存

问题描述

我需要帮助来修改此 VBA 代码以将 pdf 保存在特定文件夹中,并且我在一个名为 E 24 的单元格中计算了一个周末日期,或者如果它是另一种方式。有人可以帮忙吗?

Private Sub Picture2_Click()
    Dim OutApp As Object
    Dim OutMail As Object
    Dim v As Variant
    v = Application.GetSaveAsFilename(Range("E24").value.Format, "PDF Files (*.pdf), *.pdf")
    If Dir(v) <> "C:\Users\user\Desktop\work invoices" Then
        If MsgBox("File already exists - do you wish to overwrite it?", vbYesNo, "File Exists") = vbNo Then
            Exit Sub
        End If

        With ActiveSheet
            .ExportAsFixedFormat Type:=xlTypePDF, filename:=v, _
                                 Quality:=xlQualityStandard, IncludeDocProperties:=True, _
                                 IgnorePrintAreas:=False, From:=1, To:=3, OpenAfterPublish:=False
        End With

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

        On Error Resume Next
        With OutMail
            .To = "accounts@email.com"
            .CC = ""
            .BCC = ""
            .Subject = "Job number 1868"
            .Body = ""
            .Attachments.Add v
            .Display
        End With
        On Error GoTo 0

        Set OutMail = Nothing
        Set OutApp = Nothing
        With Application
            .ScreenUpdating = True
            .EnableEvents = True
        End With
    End If
End Sub

标签: vbaformat

解决方案


推荐阅读