开发者

Automatically name a file based on cell data when saving a spreadsheet?

I have an .xltm template spreadsheet that I'm wondering if I can get a macro to populate the "save as" file name based on cell data, is this possible?

There are over 50 people who will have this spreadsheet, it's more of a form, and we are trying to figure out a way to keep the filenames uniform. I know there i开发者_如何学Pythons the ThisWorkbook.BeforeSave, but I'm not really having any luck there. I just need it to make a file named something like $A$1 R $B$1 T $B$3.xlsx

Any ideas on how to do this?


Sure.

Sub SaveMyWorkbook()

    Dim strPath As String
    Dim strFolderPath as String

    strFolderPath = "C:\"

    strPath = strFolderPath & _
        Sheet1.Range("A1").Value & "R" & _
        Sheet1.Range("B1").Value & "T" & _
        Sheet1.Range("B3").Value & ".xlsx"

    ActiveWorkbook.SaveAs Filename:=strPath

End Sub

EDIT: After you clarified your question in your comment below, I can now safely say that the answer is: No, what you are asking is not possible.

What is possible is to put a big, fat command button on your sheet that says "Press me to save", and have that button call the above Sub. You can set a fixed folder, as in the example above, or have the user pick a folder using the FileDialog object (or the GetSaveAsFilename function, but then the user will be able to change the suggested filename, so less safe).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜