PDA

View Full Version : Saving to different folders based on part numbers in B1



cchristner
12-13-2016, 10:24 PM
Hey guys,

I was wondering if anyone knew a way to save a file to a different folder based on the part number in B1? I want to create a folder for each part number and have the file save to that folder that is the same as the current part number in B1. Here is my current save code. it saves the file as a read only copy as the part number in B1 also with a time date stamp. Any help would be greatly appreciated. Thank you.




{Sub Save()



Dim Path As String



Dim FileName1 As String



Dim DateTime As String



Dim PathAndFileName As String



Path = "C:Libraries\Documents\"



If Range("B1").Value = "" Then



MsgBox "You Must Put a Value in Cell B1!"



Exit Sub



End If



FileName1 = Range("B1")



DateTime = " (" & Format(Now, "yyyy-mm-dd hhmm AMPM") & ").xlsm"



PathAndFileName = Path & FileName1 & "-" & DateTime & ".xlsm"



Call PressTheButton



ActiveWorkbook.SaveCopyAs Filename:=PathAndFileName



SetAttr PathAndFileName, vbReadOnly



End Sub}

Geetha Gupta
12-14-2016, 08:33 PM
You can use FileCopy for this.
But you should have a folder with the name as in cell B1 - a folder for each part before this code is worked

[CODE]Dim sPathDest As String
Dim sCopy As String

sPathDest = Path of the destination folder,where the file has to be saved
sCopy = sPathDest & FileName1 &"-" & DateTime & ".xlsm"

'PathAndFileName as in your original code
FileCopy PathAndFileName sCopy

[/CODE

cchristner
12-18-2016, 09:31 PM
Thank you. That was very helpful.