简体   繁体   English

excel文件未保存到宏指定的文件路径

[英]excel file is not saving to the macro specified filepath

I have a simple macro that I want to use daily, it works fine other that it does not save where I would like it to. 我有一个我想每天使用的简单宏,它工作正常,它不会保存在我想要的地方。

Rather than saving in the desired shared network folder, it is saving in 'Documents' folder. 它保存在“Documents”文件夹中,而不是保存在所需的共享网络文件夹中。 Please help. 请帮忙。

Dim FilePath As String
Dim NewName As String

FilePath = "G:\Pricing\Gas Pricing Models\Wholesale\Basis Strips": NewName = "NYMEX" & Format(Date, "MM-DD-YYYY") & ".xlsm"

ActiveWorkbook.SaveAs Filename:=NewName, FileFormat _
:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False

ActiveWindow.SmallScroll Down:=-30
End Sub

The Filename argument of the SaveAs method should also include the filepath of the file. SaveAs方法的Filename参数还应包括文件的文件路径。 If you don't include the filepath in that argument, the file is saved to the current folder. 如果未在该参数中包含文件路径,则该文件将保存到当前文件夹中。 See this page for more information. 有关更多信息, 请参阅此页面

Your code should look like this, then: 您的代码应该如下所示,然后:

Untested 未经测试

FilePath = "G:\Pricing\Gas Pricing Models\Wholesale\Basis Strips\"  
NewName = "NYMEX" & Format(Date, "MM-DD-YYYY") & ".xlsm"

ActiveWorkbook.SaveAs Filename:=FilePath & NewName, FileFormat _
    :=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False

Note the added backslash at the end of the FilePath string. 请注意FilePath字符串末尾添加的反斜杠。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM