shiva_reshs
Board Regular
- Joined
- Sep 5, 2012
- Messages
- 68
Hi,
My Excel doesnt save after i run below VBA. with error msg as corrupted.
My Excel doesnt save after i run below VBA. with error msg as corrupted.
Code:
Sub foo2()Dim x As Workbook
Dim y As Workbook
Workbooks("TimeSheet.xlsm").Activate
ImportDir1 = Trim(Sheets("Control").Range("C5").Value)
Workbooks("TimeSheet.xlsm").Activate
ImportDir2 = Sheets("Control").Range("C6").Value
'## Open both workbooks first:
Workbooks("TimeSheet.xlsm").Activate
Set x = Workbooks.Open(ImportDir1 & "\" & Sheets("Control").Range("B5").Value & ".xlsx")
With x.Sheets("WEEK 1")
ActiveSheet.Copy After:=Workbooks("TimeSheet.xlsm").Sheets("Control")
ActiveSheet.Name = "Week1"
With Range("D1:M100")
.Value = .Value
End With
x.Close
Workbooks("TimeSheet.xlsm").Activate
Set y = Workbooks.Open(ImportDir2 & "\" & Trim(Sheets("Control").Range("B6").Value) & ".xlsx")
'Now, transfer values from x to y:
'Copy the active sheet to the end of named Workbook.
'Replace YourWorkbook.xls with the full name of the target workbook you want.
With y.Sheets("WEEK 1")
ActiveSheet.Copy After:=Workbooks("TimeSheet.xlsm").Sheets("Control")
ActiveSheet.Name = "Week2"
With Range("D1:M100")
.Value = .Value
End With
y.Close
Sheets("Week1").Select
Range("N1").Select
Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
Selection.EntireColumn.Delete
Sheets("Week1").Select
Columns("I:I").Insert Shift:=xlToRight
Application.CutCopyMode = False
'.Range("I12").Value = "NOR2"
'Call nn
End With
End With
Sheets("Week2").Select
End Sub