ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   code to save the whole folder in which is the workbook (https://www.excelbanter.com/excel-programming/333258-code-save-whole-folder-workbook.html)

Tim

code to save the whole folder in which is the workbook
 
Hi All

Is it possible to change this code:
Sub SaveBackup()
ActiveWorkbook.SaveCopyAs "d:\MyBook.xls"
End Sub
to save a copy of the Folder in which is the Book-to back up not only
€śMyBook€ť but the whole current folder with the book?


Rich_z[_10_]

code to save the whole folder in which is the workbook
 

Yep.

However, you're going to open up a whole can of worms such a
traversing your directory tree, using fileobjects and it will not b
easy

--
Rich_
-----------------------------------------------------------------------
Rich_z's Profile: http://www.excelforum.com/member.php...fo&userid=2473
View this thread: http://www.excelforum.com/showthread.php?threadid=38347


Dave Peterson[_5_]

code to save the whole folder in which is the workbook
 
This will copy the folder.

Option Explicit
Sub saveFolder()

Dim FSO As Scripting.FileSystemObject
Dim myFolder As Folder
Dim myPath As String

myPath = ActiveWorkbook.Path

If myPath = "" Then
MsgBox "please save this file first"
Exit Sub
End If

Set FSO = New Scripting.FileSystemObject

FSO.CopyFolder Source:=myPath, _
Destination:="c:\temp\backup", overwritefiles:=True

End Sub

But it doesn't do the workbook save. You may want to add that to start. (I
wasn't sure.)

Tim wrote:

Hi All

Is it possible to change this code:
Sub SaveBackup()
ActiveWorkbook.SaveCopyAs "d:\MyBook.xls"
End Sub
to save a copy of the Folder in which is the Book-to back up not only
€śMyBook€ť but the whole current folder with the book?


--

Dave Peterson

Dave Peterson[_5_]

code to save the whole folder in which is the workbook
 
That original post needed a reference to "microsoft scripting runtime".

This version doesn't.

Option Explicit
Sub saveFolder()

Dim FSO As Object
Dim myFolder As Object
Dim myPath As String

myPath = ActiveWorkbook.Path

If myPath = "" Then
MsgBox "please save this file first"
Exit Sub
End If

Set FSO = CreateObject("Scripting.FileSystemObject")

FSO.CopyFolder Source:=myPath, _
Destination:="c:\temp\backup", overwritefiles:=True

End Sub

Tim wrote:

Hi All

Is it possible to change this code:
Sub SaveBackup()
ActiveWorkbook.SaveCopyAs "d:\MyBook.xls"
End Sub
to save a copy of the Folder in which is the Book-to back up not only
€śMyBook€ť but the whole current folder with the book?


--

Dave Peterson

Tim

code to save the whole folder in which is the workbook
 


Thankyou Dave !!!
As always helpful answer from you.



All times are GMT +1. The time now is 09:20 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com