打开另存为窗口,并从单元格填充文件名和文件路径 [英] 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
这篇关于打开另存为窗口,并从单元格填充文件名和文件路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文