[英]Open save as window and populate file name and file path from cell
I'm trying to open the save as window and populate the file name and file path from a cell 我正在尝试打开另存为窗口,并从单元格填充文件名和文件路径
Here's the code I have which does populate the file name and opens the save as window in the file path but when I click save the file never shows up in the location where it was suppose to save. 这是我具有的代码,该代码确实填充文件名并在文件路径中打开另存为窗口,但是当我单击“保存”时,文件永远不会显示在应该保存的位置。
Sub Save()
'Adds formula to show file path
ActiveSheet.Range("I26") = "=LEFT(CELL(""filename"",RC),FIND(""["",CELL(""filename"",RC),1)-1)"
'Adds formula to show file name
ActiveSheet.Range("J26") = "=MID(CELL(""filename""),FIND(""["",CELL(""filename""))+1,(FIND(""]"",CELL(""filename""))-FIND(""["",CELL(""Filename""))-8))"
ActiveSheet.Calculate 'Calculate sheet
'this will remove the formula from the cell making it text only
ActiveSheet.Range("I26") = ActiveSheet.Range("I26")
ActiveSheet.Range("J26") = ActiveSheet.Range("J26")
Dim FilePath As String
Dim FileName As String
FilePath = ActiveSheet.Range("I26").Value
FileName = ActiveSheet.Range("J26").Value
Dim fPth As Object
Set fPth = Application.FileDialog(msoFileDialogSaveAs)
With fPth
.InitialFileName = FilePath & FileName & ".xlsm"
.Title = "Save your File"
.InitialView = msoFileDialogViewList
.Show
End With
End Sub
The file dialog doesn't actually save the file - it just prompts the user for a filename or allows the user to change a default filename. 文件对话框实际上并没有保存文件-它只是提示用户输入文件名或允许用户更改默认文件名。 You have to get the selected filename back and save it independently something like this:
您必须取回所选的文件名并像下面这样单独保存它:
Dim fPth As Object
Set fPth = Application.FileDialog(msoFileDialogSaveAs)
With fPth
.InitialFileName = FileName & ".xlsm"
.Title = "Save your File"
.InitialView = msoFileDialogViewList
If .Show <> 0 Then
ThisWorkbook.SaveAs FileName:=.SelectedItems(1), FileFormat:=xlWorkbookNormal
End If
End With
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.