VBA SaveAs xlsm特定名称和位置提示

时间:2015-11-24 12:03:42

标签: excel vba excel-vba

我正在尝试创建一个新工作簿,然后将其保存为xlsm格式在提示位置,文件名为:

"Combined ALC Depot Reports " & Format(Date, "MM.DD.YY")

我的代码如下。目前它会提示您输入位置,但不会填写文件名。

Sub NewWb()
Dim Aname As String
Dim fileToSaveAs As Variant

Aname = "Combined ALC Depot Reports " & Format(Date, "MM.DD.YY")
Workbooks.Add

ChDir "C:/temp/" 'Change to initial path

fileToSaveAs = Application.GetSaveAsFilename(InitialFileName:=Aname, FileFilter:="Excel Macro-Enabled Workbook (*.xlsm), *.xlsm")

 If fileToSaveAs <> False Then
     ActiveWorkbook.SaveAs FileName:=fileToSaveAs, FileFormat:=52
 End If

End Sub

任何帮助将不胜感激!谢谢!

1 个答案:

答案 0 :(得分:0)

忘记Sub NewWb() Dim Aname As String Dim fileToSaveAs As Variant Aname = "c:\temp\test" Workbooks.Add ChDir "C:\" '--->no effect fileToSaveAs = Application.GetSaveAsFilename(InitialFileName:=Aname, FileFilter:="Excel Macro-Enabled Workbook (*.xlsm), *.xlsm") If fileToSaveAs <> False Then ActiveWorkbook.SaveAs Filename:=fileToSaveAs, FileFormat:=52 End If End Sub 并将路径包含在Aname中。下面的代码工作正常,在TEMP文件夹中打开,默认名称为TEST:

while($fet_pic=mysql_fetch_array($albpic))
       {
         $album[]=$fet_pic['CONTENT_VALUE'];
         $bulk=json_decode($album);
       }