jim may
Well-known Member
- Joined
- Jul 4, 2004
- Messages
- 7,486
My first attempt at Automation -- Does anyone see any HOLES in this Code
When I F8 thru it - Excel DOES NOT OPEN for me to see the Final Destination Sheet; Someting is missing; But what?
When I F8 thru it - Excel DOES NOT OPEN for me to see the Final Destination Sheet; Someting is missing; But what?
Code:
Option Compare Database
Option Explicit
Sub ExportToMyExcel()
Dim appExcel As New Excel.Application
Dim mySourceBook As Excel.Workbook
Dim myDestinationBook As Excel.Workbook
Dim mySourceSheet As Excel.Worksheet
Dim myDestinationSheet As Excel.Worksheet
Dim Rng1 As Range
Dim Rng2 As Range
On Error Resume Next
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12, "qryDataExportedToExcel", _
"C:\Users\Jmay\Documents\Causey-Jack\CBF Project\Last_CBF_DB_Export.xlsx", True
On Error GoTo 0
Set myDestinationBook = appExcel.Workbooks.Open("C:\Users\Jmay\Documents\Causey-Jack\Ministers_Churches_Database_4.xlsm")
Set myDestinationSheet = myDestinationBook.Worksheets("Ministers")
Set mySourceBook = appExcel.Workbooks.Open("C:\Users\Jmay\Documents\Causey-Jack\CBF Project\Last_CBF_DB_Export.xlsx")
Set mySourceSheet = mySourceBook.Worksheets("qryDataExportedToExcel")
Set Rng1 = mySourceSheet.UsedRange
Set Rng2 = Rng1.Offset(1, 0).Resize(Rng1.Rows.Count - 1)
Rng2.Copy
myDestinationSheet.Range("A4").PasteSpecial (xlPasteValues)
Set Rng1 = Nothing
Set Rng2 = Nothing
Set myDestinationSheet = Nothing
Set mySourceSheet = Nothing
Set myDestinationBook = Nothing
Set mySourceBook = Nothing
Set appExcel = Nothing
End Sub