我制作了一个带有一些按钮的工作表,可以快速保存、另存为和打印,但是当我另存为保存在 Google Drive 文件夹中时,因为是当前文件所在的位置,但我想保存在桌面上但我找不到一种在不破坏文件名的情况下进行此更改目录的方法。当另存为时,我将文件自动重命名为两个单元格(B10 和 B15)的值,但是当我用我在互联网上找到的某些方法更改目录时,不起作用。我无法正确设置名称和目录而不会出错。
我当前的代码:
Sub SaveAs()
On Error GoTo ErrorSaveAs
Dim ClientName
ClientName = Range("B10").Value & " - " & Range("B15").Value
ActiveWorkbook.SaveAs FileName:="ClientName", FileFormat:=xlOpenXMLWorkbookMacroEnabled
MsgBox "O arquivo foi salvo no seu Desktop.", vbVertical, "Sucesso! - Garage Audax" 'Success message after saving it
Exit Sub
ErrorSaveAs: MsgBox "Ocorreu um erro. Revise as informações e tente novamente.", vbVertical, "Ops! - Garage Audax" 'Error message in case of any error
End Sub
最佳答案
您可以获取当前用户路径文件夹并添加桌面并加入桌面和文件名。
将桌面文件夹调暗为字符串
desktopFolder = vba.environ("USERPROFILE") & "\Desktop\myFile.xlsm"
关于excel - VBA - 使用单元格值名称更改目录文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64270617/