VBA-使用预定义的名称将文件另存为PDF到特定位置

时间:2019-09-19 09:26:56

标签: excel vba

下面的代码可以正常工作,直到生成文件名。它会选择正确的文件夹位置,但文件名为空白。enter image description here

如果我选择本地计算机上的某个位置,则将显示文件名。你能告诉我我该怎么做吗?

Private Sub CBSaveasPDF_Click()
    Dim FileAndLocation As Variant
    Dim strPathLocation As String
    Dim strFilename As String
    Dim strPathFile As String        


    strPathLocation = "http://teams.xxx.intranet/sites/bipm/test/test/test/test/test/"
    strFilename = Me.Range("D8") & " -" & Me.Range("D7") & " -" & Me.Range("J7") & " " & Me.Range("B3")
    strPathFile = strPathLocation & strFilename

    FileAndLocation = Application.GetSaveAsFilename _
                        (InitialFileName:=strPathLocation & strFilename, _
                        filefilter:="PDF Files (*.pdf), *.pdf", _
                        Title:="Select Folder and FileName to save")
        If FileAndLocation = "False" Then
            MsgBox ("Document not saved")
            Exit Sub
        End If

        Me.ExportAsFixedFormat _
            Type:=xlTypePDF, _
            Filename:=strFilename, _
            Quality:=xlQualityStandard, _
            IncludeDocProperties:=True, _
            IgnorePrintAreas:=False, _
            OpenAfterPublish:=True

0 个答案:

没有答案