Caveman1964
Board Regular
- Joined
- Dec 14, 2017
- Messages
- 127
- Office Version
- 2016
- Platform
- Windows
Hi All!
New to VBA. Struggling with this. Would appreciate any help
I want to,
open a workbook
save it in a new directory from created from cell h5 value
F:\Job Packets"H5"\my new file name (which will be value from h5 as well followed by the word "lot"
I have macro to save work book as the cell plus the lot and a separate to make new folder but cannot figure out how to have it make new folder and save new filename in the new folder.
Embarrassed to post this macro, yes I am aware this is crap please rewrite whole thing if needed. I need a chdir in there somewhere.
Thank You ahead of time.
I'll send you a six pack or something.
Thanks Caveman
Sub CreateFolderAndCopy()
Dim fileName As String
With Sheets(1)
If (.Range("H5") = vbNullString) Then Exit Sub
On Error Resume Next
MkDir "F:\Job Packets" & .Range("H5")
On Error GoTo 0
Dim NewFN As Variant
NewFN = "F:\Job Packets\ " & Range("H5").Value & ("LotMaterial") & ".xlsm"
ActiveWorkbook.SaveAs NewFN, FileFormat:=xlOpenXMLWorkbookMacroEnabled
ActiveWorkbook.Close
End With
End Sub
New to VBA. Struggling with this. Would appreciate any help
I want to,
open a workbook
save it in a new directory from created from cell h5 value
F:\Job Packets"H5"\my new file name (which will be value from h5 as well followed by the word "lot"
I have macro to save work book as the cell plus the lot and a separate to make new folder but cannot figure out how to have it make new folder and save new filename in the new folder.
Embarrassed to post this macro, yes I am aware this is crap please rewrite whole thing if needed. I need a chdir in there somewhere.
Thank You ahead of time.
I'll send you a six pack or something.
Thanks Caveman
Sub CreateFolderAndCopy()
Dim fileName As String
With Sheets(1)
If (.Range("H5") = vbNullString) Then Exit Sub
On Error Resume Next
MkDir "F:\Job Packets" & .Range("H5")
On Error GoTo 0
Dim NewFN As Variant
NewFN = "F:\Job Packets\ " & Range("H5").Value & ("LotMaterial") & ".xlsm"
ActiveWorkbook.SaveAs NewFN, FileFormat:=xlOpenXMLWorkbookMacroEnabled
ActiveWorkbook.Close
End With
End Sub