Moving a workbook

D

Daminc

This macro has gone through a lot of changes as you can see with all the
comment tags.

I'm trying to find a workbook in a folder and then move it to another
folder with an altered name.


Code:
--------------------
Public Sub name_of_workbook()

Dim bookpath As Variant
Dim sourcepath As Variant
Dim Wrkbook As Workbook
Dim archivepath As String
Dim wkbkname As String
Dim wkbkaddr As String
Dim actiondate As Variant
Dim dateofchange As String
Dim newname As String

sourcepath = "P:\VBA training\Test_folder"

For Each Wrkbook In sourcepath
bookpath = Wrkbook.FullName


'bookpath = ActiveWorkbook.FullName
archivepath = "P:\VBA training\archive\"
wkbkname = bookpath.Name
'wkbkaddr = ActiveWorkbook.Address
actiondate = Format(Now(), "ddmmyyyy")
'FormatDateTime(actiondate, 2)
'dateofchange = (actiondate, "dd mm yy")
newname = (actiondate) & "_" & wkbkname
'bookpath.Close
bookpath.Move "archivepath & newname"
Next Wrkbook

End Sub
 
D

Daminc

I've got a base solution if anyone is interested:

The code gets the workwook in the source folder and then moves it into
an archive folder with date of the move attached to the front.


Code:
--------------------
Public Sub Move_rename_workbook()

Dim bookpath As String
Dim wkbkname As String
Dim actiondate As String
Dim dateofchange As String
Dim newname As String
Dim OldFilePath As String
Dim NewFilePath As String

Const sourcepath = "P:\VBA training\Test_folder\"
Const archivepath = "P:\VBA training\archive\"

wkbkname = Dir(sourcepath & "*.xls")

bookpath = sourcepath & wkbkname

actiondate = Format(Now(), "ddmmyyyy")

newname = (actiondate) & "_" & wkbkname

OldFilePath = bookpath
NewFilePath = archivepath & newname

Name OldFilePath As NewFilePath

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top