Code to move excel file from one folder to another folder

rwilard

New Member
Joined
Nov 29, 2018
Messages
9
Hello, I have been unable to find a code that allows me to move the current workbook from one folder into another so I thought of the idea of a save as that saves in the desired folder but also kills the file in the current folder. I have gotten the save to work but not the kill. The file is present in both folders, can someone help me?

path = "I:\AAA-PURCHASE ORDERS\test1"
path2 = "I:\AAA-PURCHASE ORDERS\test2"
filename1 = "PO#_" & Range("H4").Text & "_" & Range("C10").Text & "_" & Range("H7").Text & "_" & Range("F49").Text
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs FileName:=path2 & filename1 & ".xlsm", FileFormat:=xlOpenXMLWorkbookMacroEnabled
MsgBox "File Saved"
Application.DisplayAlerts = True



Kill path & filename1
Application.ActiveWorkbook.Close False
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Upvote 0
follow path with backslash before Filename
- seems missing generally in your code
c:\folder\subfolder\filename.xlsm
 
Last edited:
Upvote 0
I haven't tried this, but look at post # 3 in this thread:

https://www.mrexcel.com/forum/excel-questions/965244-how-delete-workbook-automatically-macro.html

Also, instead of a SaveAs/Kill combination, you may want to try

Code:
Name .FullName As path2 & .Name

https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/name-statement

I haven't tried that in your particular situation either, but it may be safer.


I keep getting a compile error expected end of statement and then it highlights the As
 
Upvote 0
What didn't work?
 
Last edited:
Upvote 0
What did not work?
Post the actual line of code
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top