SysDupe123
Technical User
I've got an Excel Macro in Access that works once and then gives an error or does not perform correctly afterwards. I close the database and re-open it and it works fine the first time only again.
Here is the Excel part of the code. I'm trimming a part of an Excel file and importing it into Access.
Set XLbase = New Excel.Application
Set XLNwSt = XLbase.Workbooks.Add
Set XLSheet = XLbase.Workbooks.Open(MatrixFile)
XLSheet.ActiveSheet.Copy XLNwSt.ActiveSheet
With XLNwSt
'delete first column
Range("A1").Activate
Columns("A:A").Select
Pause (2)
Selection.Delete Shift:=xlToLeft
'copy paste values
Cells.Select
Pause (2)
Selection.Copy
Pause (4)
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
'Delete top 8 rows
Pause (10)
Rows("1:8").Select
Pause (2)
Selection.Delete Shift:=xlUp
Pause (2)
'Delete unneeded columns at right
ActiveWindow.SmallScroll ToRight:=6
Pause (2)
Columns("S:S").Select
Pause (1)
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlToRight)).Select
Pause (1)
Selection.Delete Shift:=xlToLeft
'sort to remove excess lines
Cells.Select
Pause (1)
Range("A2").Activate
Selection.Sort Key1:=Range("A1"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
Range("A3").Select
Pause (1)
Selection.End(xlDown).Select
Selection.Offset(1, 0).Select
Pause (1)
Selection.EntireRow.Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Delete Shift:=xlUp
End With
XLSheet.Close False
Set XLSheet = Nothing
XLNwSt.SaveAs NwMatrixFile & ".txt", xlTextMSDOS
XLNwSt.Close True
XLbase.Quit
Set XLNwSt = Nothing
Set XLbase = Nothing
Any ideas on how to get it working every time? I'm getting a 1004 Error.
Here is the Excel part of the code. I'm trimming a part of an Excel file and importing it into Access.
Set XLbase = New Excel.Application
Set XLNwSt = XLbase.Workbooks.Add
Set XLSheet = XLbase.Workbooks.Open(MatrixFile)
XLSheet.ActiveSheet.Copy XLNwSt.ActiveSheet
With XLNwSt
'delete first column
Range("A1").Activate
Columns("A:A").Select
Pause (2)
Selection.Delete Shift:=xlToLeft
'copy paste values
Cells.Select
Pause (2)
Selection.Copy
Pause (4)
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
'Delete top 8 rows
Pause (10)
Rows("1:8").Select
Pause (2)
Selection.Delete Shift:=xlUp
Pause (2)
'Delete unneeded columns at right
ActiveWindow.SmallScroll ToRight:=6
Pause (2)
Columns("S:S").Select
Pause (1)
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlToRight)).Select
Pause (1)
Selection.Delete Shift:=xlToLeft
'sort to remove excess lines
Cells.Select
Pause (1)
Range("A2").Activate
Selection.Sort Key1:=Range("A1"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
Range("A3").Select
Pause (1)
Selection.End(xlDown).Select
Selection.Offset(1, 0).Select
Pause (1)
Selection.EntireRow.Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Delete Shift:=xlUp
End With
XLSheet.Close False
Set XLSheet = Nothing
XLNwSt.SaveAs NwMatrixFile & ".txt", xlTextMSDOS
XLNwSt.Close True
XLbase.Quit
Set XLNwSt = Nothing
Set XLbase = Nothing
Any ideas on how to get it working every time? I'm getting a 1004 Error.