Line not executable on Sheets.New.Name (very novice)

kvilain

New Member
Joined
Oct 23, 2013
Messages
1
I apologize in advance for any noob poster mistakes - I am very novice, trying to edit an Access database. I am trying to upload .xlsx data by changing a hard-coded workbook and worksheet name to a more flexible one. The worksheet name includes a date that will be changing every time this is run, so I am trying to refer to it as ActiveSheet or Sheet(1). This seems to be okay, but I also need to copy the date on Sheet(1) to a new sheet. From searching forums, it seems like Sheets.New.Name = "namexxx" should work, but when I run, VBA gives me a "Line is not executable" error with that line highlighted (in red in my code, below).

I'm not even clear what "With xls" means or if it is why suddenly the code I'm editing should begin with "." This is how novice I am, so please be forgiving! Thanks for any insight. Excel and Access are 2007; Windows is XP.

Kate


Rich (BB code):
Sub cmdLoadFile_Click()
Rich (BB code):
Rich (BB code):
Dim xls As Excel.Application
Set xls = CreateObject("Excel.Application")
Dim ws As Worksheet


xls.Visible = True
xls.Workbooks.Open (Me.txtInputFile)


'Delete All Worksheets except CoreLab and Implant Tracker Sheets
xls.DisplayAlerts = False
For Each ws In ActiveWorkbook.Worksheets
If ws.Name Like "LIBERTY_PROC_export" & "*" = False Then
            If ActiveWorkbook.Worksheets.Count = 1 Then
                MsgBox "There is only one sheet left and you cannot delete it"
            Else
                ws.Delete
             
            End If
          
            End If
            
Next
xls.DisplayAlerts = True


With xls
    .Sheets(1).Select
    .DisplayAlerts = False
    .Sheets(1).Name = "Original"
    .Sheets.Add.Name = "IndexFormatted"
    .Sheets("Original").Select
    .Range("A1:J2999").Select
    .Selection.Copy
    .Sheets("IndexFormatted").Select
    .Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    .Sheet1.Delete
    .Sheets("IndexFormatted").Select

 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().

Forum statistics

Threads
1,215,308
Messages
6,124,173
Members
449,146
Latest member
el_gazar

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