首页 > 解决方案 > VBA - 将文件另存为 PDF 到具有预定义名称的特定位置

问题描述

下面的代码可以正常工作,直到生成文件名。它会选择正确的文件夹位置,但文件名是空白的。在此处输入图像描述

如果我在本地机器上的某个位置选择位置,则会出现文件名。你能告诉我我应该怎么做吗?

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

标签: excelvba

解决方案


推荐阅读