andrea_bertorelli
New member
- Local time
- Yesterday, 22:23
- Joined
- Aug 27, 2008
- Messages
- 4
Dear all,
I am new to VBA programming and I need some support (actually as much support as I can get...). I created a module in Access that opens a workbook, copies data from one tab to another and then saves and closes the workbook. To capture a defined set of data in the tab I am using the xlDown function; the issue is that I get the "variable not defined" error, and if I declare it I get again an error, this time the "Sub or Function not defined" kind. attached is the code:
------------------------------
Option Compare Database
Option Explicit
Sub OpenSpecific_xlFile()
Dim oXL As Object
Dim oExcel As Object
Dim sFullPath As String
Set oXL = CreateObject("Excel.Application")
On Error GoTo ErrHandle
sFullPath = CurrentProject.Path & "\01.S-DIFOT_NewSolution.xls"
With oXL
.Visible = True
.Workbooks.Open (sFullPath)
.Range("A2:K65536").Select
.Selection.ClearContents
.Sheets("SIFOT").Select
.Range("K92:A" & Range("A92").End(xlDown).Row).Select
.Selection.Copy
.Sheets("SDIFOT_IMPORT").Select
.Range("A2").Select
.Selection.PasteSpecial
.Range("A2").Select
.Application.CutCopyMode = False
.ActiveWorkbook.Save
.ActiveWorkbook.Close
End With
ErrExit:
Set oXL = Nothing
Exit Sub
ErrHandle:
oXL.Visible = False
MsgBox Err.Description
GoTo ErrExit
End Sub
----------------------------------------------
Could you shed some light? Your help is much appreciated.
Thanks
Andrea
I am new to VBA programming and I need some support (actually as much support as I can get...). I created a module in Access that opens a workbook, copies data from one tab to another and then saves and closes the workbook. To capture a defined set of data in the tab I am using the xlDown function; the issue is that I get the "variable not defined" error, and if I declare it I get again an error, this time the "Sub or Function not defined" kind. attached is the code:
------------------------------
Option Compare Database
Option Explicit
Sub OpenSpecific_xlFile()
Dim oXL As Object
Dim oExcel As Object
Dim sFullPath As String
Set oXL = CreateObject("Excel.Application")
On Error GoTo ErrHandle
sFullPath = CurrentProject.Path & "\01.S-DIFOT_NewSolution.xls"
With oXL
.Visible = True
.Workbooks.Open (sFullPath)
.Range("A2:K65536").Select
.Selection.ClearContents
.Sheets("SIFOT").Select
.Range("K92:A" & Range("A92").End(xlDown).Row).Select
.Selection.Copy
.Sheets("SDIFOT_IMPORT").Select
.Range("A2").Select
.Selection.PasteSpecial
.Range("A2").Select
.Application.CutCopyMode = False
.ActiveWorkbook.Save
.ActiveWorkbook.Close
End With
ErrExit:
Set oXL = Nothing
Exit Sub
ErrHandle:
oXL.Visible = False
MsgBox Err.Description
GoTo ErrExit
End Sub
----------------------------------------------
Could you shed some light? Your help is much appreciated.
Thanks
Andrea