Weird Issue with my code....

Mini-Travis

New Member
Joined
Nov 30, 2010
Messages
5
Good Afternoon,

I am having a weird issue with a snipit of my code.
My goal is to be able to copy a worksheet from one workbook to another. This is simple enough but I am running into an issue with it. My activeworkbook has a sheet in it called CR-####. I am opening a workbook in a database and trying to copy the activesheet into the database workbook. The database workbook also has a sheet named CR-####, so I am renaming the one that I add.

Once again this is simple stuff, but the weird part is the code crashes if I don't have the VB editor up. In other words if I open excel and run the macro it crashes, but if I open excel and hit alt F11 and still run the macro as normal it works perfectly fine.

I have isolated the part of the code that fails, but I can't understand why it fails if I do not have VBA up.


Code:
   ''This is where I start running into problems
   Workbooks(CurrentBook).Activate
    Worksheets(CRNumber).Select
    Application.DisplayAlerts = False
 
    Filenameit = "Path" & CRWorksheet
    Workbooks.Open Filename:=Filenameit, Notify:=False
    DataBaseWorkbook = CRWorksheet
    DataBaseWorkbook = Left(DataBaseWorkbook, Len(DataBaseWorkbook) - 5)
    Count = ActiveWorkbook.Worksheets.Count
    ReNameMe = CRNumber & " Update #" & Count
    CountNew = Count + 1
    OldName = CRNumber & " (2)"
 
    Workbooks(DataBaseWorkbook).Worksheets(CRNumber).Select
 
 
    Worksheets(CRNumber).Copy Before:=Workbooks(DataBaseWorkbook).Sheets(1)
        Workbooks(DataBaseWorkbook).Activate
 
        Workbooks(DataBaseWorkbook).Worksheets(CRNumber).Select
        Workbooks(DataBaseWorkbook).Worksheets(OldName).Select
        Workbooks(DataBaseWorkbook).Worksheets(OldName).Name = ReNameMe
        Workbooks(DataBaseWorkbook).Worksheets(ReNameMe).Select
        Cells.Select
        Selection.Locked = True
 
         Workbooks(DataBaseWorkbook).Worksheets(ReNameMe).Protect ("Password"), AllowFormattingCells:=True, AllowFormattingColumns:=True, AllowFormattingRows:=True
 
         Workbooks(DataBaseWorkbook).Close (True)

Any takers? Also my code may not be the most effective way of doing this, but I have scrached my head at this for hours now.
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.

Forum statistics

Threads
1,224,586
Messages
6,179,712
Members
452,939
Latest member
WCrawford

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