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
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