使用VBA中的宏保存在新文件中

时间:2014-04-14 20:19:57

标签: excel excel-vba vba

我使用下面的代码,但是当我运行它时,它只保存最后一部分(& Day(现在)&“ - ”& Month(Now)&“ - ”& Year(Now) )这个名字。没有考虑de string“Asesor”。我不知道我错过了哪一部分:

Sub SaveFile()

 Dim Asesor As String
 Asesor = Range("B3").Value

Dim DestFile
DestFile = "C:\Users\ST\"

Application.ScreenUpdating = False
Workbooks("Grillas_QA.xlsm").Activate
ActiveSheet.Range("A1:K51").Select
Selection.Copy

Workbooks.Add

Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
    SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
ActiveWindow.DisplayGridlines = False


Application.DisplayAlerts = False

这是我保存文件的地方。

ActiveWorkbook.SaveAs Filename:=DestFile & Asesor & " " & Day(Now) & "-" & Month(Now) & "-" & Year(Now), _
FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False

Thnx提前寻求帮助。

1 个答案:

答案 0 :(得分:1)

作为评论的后续内容,下一行

Asesor = Range("B3").Value

应该更改为:

Asesor = ThisWorkbook.Worksheets("Sheet1").Range("B3").Value

另外作为推荐,我建议你阅读这篇文章:How to avoid using Select/Active statements