另存为可变文件路径

时间:2018-01-04 02:58:13

标签: excel vba excel-vba

尝试使用Excel宏,一旦填充某些单元格,将自动保存工作簿。宏将检查何时对特定单元格进行更改,然后使用可变数据通过按年组织的文件夹系统保存工作簿和季度,同时为工作簿提供基于当前日期和单元格编号的名称。宏还将检查网络路径(它在服务器上)是否已连接,如果没有,则退出该子网。我收到编译错误"预期:声明结束"在

Set mTitle = Year(Now)," & . & ", Month(Now), " &.& ", Day(Now), " & - & ", ActiveWorkbooks.Sheets("Control").Cells(1, "C")

我想使用以下格式保存工作簿:Year.Month.Day - CellValue,但看起来VBA不像句点。我怎么解决这个问题?完整代码如下。

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim cYear As String
Dim Quarter As String
Dim fdObj As Object
Dim mTitle As String
Dim sCheck

Application.ScreenUpdating = False


Set cYear = Year(Now)
Set Quarter = (Month(Now) + 2) \ 3
Set fdObj = CreateObject("Scripting.FileSystemObject")
sCheck = "S:\Estimating Data\Estimates\test.txt"
Set mTitle = Year(Now)," & . & ", Month(Now), " &.& ", Day(Now), " &.& ", ActiveWorkbooks.Sheets("Control").Cells(1, "C")

If Intersect(Target, Range("C1:C5")) Is Nothing Then
Exit Sub
Else
 If WorksheetFunction.CountA(Range("C1:C5")) = 0 Then
 Exit Sub
 Else

 Shell ("Net View \\S:\ > " & vsFileName)
    If FileLen(vsFileName) = 0 Then
    Exit Sub

Else

        If fdObj.FolderExists("S:\Estimating Data\Estimates\" & cYear & "\""Q" & Quarter & ".*xlsm") Then
 ActiveWorkbook.SaveAs Filename:="S:\Estimating Data\Estimates\" & cYear & "\""Q" & Quarter & "\" & mTitle & ".*xlsm"
  Else
    fdObj.CreateFolder ("S:\Estimating Data\Estimates\" & cYear & "\""Q" & Quarter & ".*xlsm")

        End If

    End If

 End If

End If

End Sub

0 个答案:

没有答案