将excel另存为pdf,将文件名称另存为变量值

时间:2015-05-07 21:21:18

标签: excel vba excel-vba

我试图将选择保存为pdf,一切正常,但我无法保存文件和特定名称,我希望名称是报告Sub和日期和时间...它工作正常,除非我尝试把今天的日期和时间...... 这是我的代码

Sub guardar_pdf()
'
' Macro7 Macro
'

'
    Range("A1:Q4").Select


    With ActiveSheet.PageSetup

        .Orientation = xlLandscape
        .Zoom = 60
        .PrintGridlines = True
    End With

     Dim fe As String
    fe = now

     With Selection

    .ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
            "C:\Users\Diego\Dropbox\informes\informe"&fe, Quality:=xlQualityStandard, _
            IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=True
End With



End Sub

1 个答案:

答案 0 :(得分:2)

有几种方法可以解决这个问题。

fe = Format(Now, "yyyymmdd_hhmmss")

或者忽略它并且只是这样做

"C:\Users\Diego\Dropbox\informes\informe" & Format(Now, "yyyymmdd_hhmmss")