从单元格中选择保存路径

时间:2015-05-28 20:24:42

标签: excel vba excel-vba

我有以下代码:

Const SAVE_PATH = "S:\Divisional Support\RVU Programs\Payroll 2015\2015-04 April\PDF's\Baptist Easley"

'paste file destination in the above location'

   Dim cell As Range
   Dim wsSummary As Worksheet
   Dim counter As Long

   Set wsSummary = Sheets("PERFORM. SUM. - EASLEY")

   For Each cell In Worksheets("NAME KEY").Range("$H:$H")
      If cell.Value <> "" Then

         'progress in status bar
         counter = counter + 1
         Application.StatusBar = "Processing file: " & counter & "/1042"

         With wsSummary
            .Range("$A$4").Value = cell.Value
            .ExportAsFixedFormat _
                  Type:=xlTypePDF, _
                  Filename:=SAVE_PATH & "\" & cell.Value & ".pdf", _
                  Quality:=xlQualityStandard, _
                  IncludeDocProperties:=True, _
                  IgnorePrintAreas:=False, _
                  OpenAfterPublish:=False
         End With
      End If
  Next cell


   Set wsSummary = Nothing
End Sub

我的问题很简单,而不必进入代码来更改保存位置:Const SAVE_PATH = "S:\Divisional Support\RVU Programs\Payroll 2015\2015-04 April\PDF's\Baptist Easley"

我希望能够在单元格J2中发布该位置,我将如何编码?

1 个答案:

答案 0 :(得分:4)

  

我希望能够在单元格J2中发布该位置,我将如何编写该代码?

实际上非常简单

替换

FileName:=SAVE_PATH & "\" & cell.Value & ".pdf"

FileName:=Thisworkbook.Sheets("Sheet1").Range("J2").Value & _
          "\" & cell.Value & ".pdf"

ThisworkbookSheet1更改为相关的工作簿或工作表。