![](/img/trans.png)
[英]VBA excel - How to 'saveas' file without preserving the first file
[英]Setting the filename for an Excel file in the SaveAs window without sendkeys in vba
我想知道 SaveAs window 文件名文本框是否有一個我可以設置文本的屬性。 目前我正在使用 sendkeys function,在我遇到括號等特殊字符之前,它適用於大多數情況。
我目前的代碼基本上是:
SaveFldr = "S:\Desktop\grape
Filename = "Grape Data"
Application.SendKeys "{F12}" ' opens the save as window
Application.SendKeys SaveFldr & Filename & ".pdf"
Application.SendKeys "{Enter}"
基本上我正在尋找一種方法來設置沒有發送密鑰 function 的文件名。例如..
Filename.Textbox = Filename
** 假設 SaveAs window 中的文本框被命名為。
您可以使用如下代碼
Sub CallSaveAs()
Dim fileSaveName As Variant
Dim SaveFldr As String
Dim fileName As String
SaveFldr = "S:\Desktop\grape"
fileName = "Grape Data"
fileSaveName = Application.GetSaveAsFilename( _
fileFilter:="PDF Files (*.PDF), *.pdf", _
InitialFileName:=SaveFldr & Application.PathSeparator & fileName)
If Not TypeName(fileSaveName) = "Boolean" Then
MsgBox "Save as " & fileSaveName
' Save the sheetas PDF
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, fileName:=fileName
End If
End Sub
End Sub
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.