Hello everyone
I know that there is a method SaveCopyAs method in excel that creates a copy of the workbook to a specific path.
Is there an approach using Shell to do such a task?
Save copy of workbook using Shell
-
- PlatinumLounger
- Posts: 4913
- Joined: 31 Aug 2016, 09:02
-
- Administrator
- Posts: 78481
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Save copy of workbook using Shell
Yes:
Code: Select all
Shell "cmd.exe /c copy ""C:\Folder1\ThisWorkbook.xlsm"" ""C:\Folder2\ThatWorkbook.xlsm""", vbHide
Best wishes,
Hans
Hans
-
- PlatinumLounger
- Posts: 4913
- Joined: 31 Aug 2016, 09:02
Re: Save copy of workbook using Shell
Great .. Replacing the quotes is a nightmare in such lines. How can I replace the paths with variables so as to make this line more flexible?
-
- Administrator
- Posts: 78481
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Save copy of workbook using Shell
Those double double quotes are actually only needed if the path+filename contains spaces, so in the example in my previous reply, you might omit them. But in general, it's safer to keep them.
Code: Select all
Dim strSource As String
Dim strTarget As String
strSource = "C:\Folder1\ThisWorkbook.xlsm"
strTarget = "C:\Folder2\ThatWorkbook.xlsm"
Shell "cmd.exe /c copy " & Chr(34) & strSource & Chr(34) & " " & Chr(34) & strTarget & Chr(34), vbHide
Best wishes,
Hans
Hans
-
- PlatinumLounger
- Posts: 4913
- Joined: 31 Aug 2016, 09:02
Re: Save copy of workbook using Shell
Thanks a lot for these treasures my tutor.