我有一个电子表格,每张纸上都有一个保存按钮。这些按钮当前将工作表作为 PDF 文件保存到任何用户的桌面上。有人问我是否可以在执行此操作时使按钮在桌面上创建一个标题为"BSInHouseAssets"的新文件夹。 我猜我们会在某个时候使用 MKdir......但我需要帮助。下面是保存文件的宏的当前部分。
Function SpecialFolderPath() As String
Dim objWSHShell As Object
Dim strSpecialFolderPath
'On Error GoTo ErrorHandler
' Create a shell object
Set objWSHShell = CreateObject("WScript.Shell")
' Find out the path to the passed special folder,
' just change the "Desktop" for one of the other options
SpecialFolderPath = objWSHShell.SpecialFolders("desktop")
' Clean up
Set objWSHShell = Nothing
Exit Function
ErrorHandler:
MsgBox "Error finding " & strSpecialFolder, vbCritical + vbOKOnly, "Error"
End Function
mkdir CreateObject("wscript.shell").specialfolders("desktop") & "MyFolder"
应该做这个技巧
strPath = "C:Users" & Environ("UserName") & "Desktop"
strFolderName = "test1"
strFullPath = strPath & strFolderName & ""
If Dir(strPath & strFolderName, vbDirectory) = "" Then
MkDir strFullPath
End If
ActiveWorkbook.SaveAs Filename:=strFullPath & "workbookname1", _
FileFormat:=xlOpenXMLWorkbookMacroEnabled