【问题标题】:Button to show Save As dialog, then save to a set location按钮显示另存为对话框,然后保存到设置的位置
【发布时间】:2020-07-30 08:48:03
【问题描述】:

我已经被这个问题困扰了一段时间,非常感谢您的帮助。

当工作簿关闭时,我已经有了这个概念,但它所做的只是保存到指定的位置。现在,我想对其进行调整,一旦按下按钮,它将要求用户保存到一个位置,然后保存后,excel 会将其保存到我选择的另一个位置。

按下按钮时,我不断收到错误消息“参数不是可选的”。

谢谢。

Private Sub Save(Cancel As Boolean)
  
NameOfWorkbook = Left(ThisWorkbook.Name, (InStrRev(ThisWorkbook.Name, ".", -1, vbTextCompare) - 1))

Dim varResult As Variant
'displays the save file dialog
varResult = Application.GetSaveAsFilename
'checks to make sure the user hasn't canceled the dialog
If varResult <> False Then
Cells(2, 1) = varResult

MyMsg = NameOfWorkbook + " " & "saved to return note folder"

MsgBox MyMsg

'Create and assign variables
Dim saveLocation As String
saveLocation = "S:\Office information\Returns\Return Notes\" + NameOfWorkbook

'Save Active Sheet(s) as PDF
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
    Filename:=saveLocation

End If
End Sub

【问题讨论】:

  • Private Sub Save(Cancel As Boolean) 应该是Private Sub Save()

标签: excel vba save save-as


【解决方案1】:

您不使用 sub 参数,因此正如 Siddharth 指出的那样,您应该更正 Private Sub Save()

此外,Save 是 excel 中的保留字,所以我不会将其用作子名称。

【讨论】:

  • 谢谢 ECO 和 Siddharth,这很奏效!我也将更改我的子名称。我似乎也遇到了另一个错误。该文件实际上并未按预期保存,该文件不存在,但我的快速访问将它们显示在最近的文件下。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-07-01
相关资源
最近更新 更多