excel getting corrupted after this RUN

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.

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
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.

Forum statistics

Threads
1,224,823
Messages
6,181,182
Members
453,021
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top