indupriya9
Programmer
I have a requirement to copy the workbook into a new workbook. I cannot use the savecopyas method as it copies all the macros as well. I want to copy values and formats from each worksheet into worksheets in a different workbook.
The error I get is 'object required'
The code I wrote so far is as follows:
Can anyone please tell me what I am doing wrong?
Regards
ip
The error I get is 'object required'
The code I wrote so far is as follows:
Code:
Sub fSaveWorkbookData() 'Executed when F6 is pressed'
Dim oName As String
Application.DisplayAlerts = False
oName = "ProgressData"
Set SrcBook = ThisWorkbook
Set NewBook = Workbooks.Add
SrcBook.Activate
'j = 1
For i = 1 To Worksheets.Count
With SourceWB
.Worksheets(i).Copy <<<<< Error here <<<<<
With .Worksheets(i)
.UsedRange.Copy
.Range("A1").PasteSpecial Paste:=xlValues
Set NewWB = Workbooks.Add
.Move Before:=NewWB.Sheets(i)
End With
End With
'ActiveSheet.Cells.Copy
'NewBook.Activate
'If j <= 3 Then
'NewBook.Worksheets(j).Range("A1").PasteSpecial xlPasteValues
'Else
'NewBook.Worksheets.Add
'NewBook.Worksheets(j).Range("A1").PasteSpecial xlPasteValues
'End If
'j = j + 1
SrcBook.Activate
Next i
NewBook.Activate
oName = "c:\" + oName + ".xls"
ActiveWorkbook.Close savechanges:=True, Filename:=oName
MsgBox (oName + " has been saved to 'c:' directory")
Application.DisplayAlerts = True
End Sub
Can anyone please tell me what I am doing wrong?
Regards
ip