![](/img/trans.png)
[英]Open save window in file path from cell and populate filename from cell
[英]Open save as window and populate file name and file path from cell
我正在嘗試打開另存為窗口,並從單元格填充文件名和文件路徑
這是我具有的代碼,該代碼確實填充文件名並在文件路徑中打開另存為窗口,但是當我單擊“保存”時,文件永遠不會顯示在應該保存的位置。
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
文件對話框實際上並沒有保存文件-它只是提示用戶輸入文件名或允許用戶更改默認文件名。 您必須取回所選的文件名並像下面這樣單獨保存它:
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.