Hi All,
I need your help in fixing the following code, not sure why it's not working the way I want it to be. Please see below for more details:
In the following code I'm trying to save files with specific file name and the value has to be taken from Sheet1, cell N2 of the Original file.
Can you please let me know why it's not happening and guide me accordingly? I'm badly in need of your help.
I need your help in fixing the following code, not sure why it's not working the way I want it to be. Please see below for more details:
In the following code I'm trying to save files with specific file name and the value has to be taken from Sheet1, cell N2 of the Original file.
Can you please let me know why it's not happening and guide me accordingly? I'm badly in need of your help.
Code:
Sub Copy_NewBook()
Dim sPath As String
Dim twbk As Workbook
Dim oWbK As Workbook
Dim Sh As Variant
Dim FName As String
Dim FPath As String
sPath = "C:\Users\xxxx\Desktop\Reports\Template.xlsx"
Set twbk = ThisWorkbook
Set oWbK = Workbooks.Open(sPath)
For Each Sh In twbk.Worksheets
If Sh.Name <> "CC" Then
GoTo 12
Else
GoTo 10
End If
12 Sh.Range("B5", Sh.Range("B5").End(xlToRight).End(xlDown)).Copy
oWbK.Worksheets(Sh.Name).Range("B3").PasteSpecial Paste:=xlPasteValues
Next Sh
'File name has to be with file Owner's name, which is to be taken from below address, i.e. Sheet1, N2 cell ref.
FName = twbk.Sheets("sheet1").Range("N2").Value
FPath = "C:\Users\xxxx\Desktop\Reports\Uploads\"
10 oWbK.SaveAs FileName:=FPath & FName & "_" & Format(Now(), "yyyymmdd hhmm AMPM"), FileFormat:=51, Password:="", _
WriteResPassword:="", ReadOnlyRecommended:=False, CreateBackup:=False
oWbK.Close saveChanges:=False
' MsgBox ("Report Generated !!!")
End Sub