silentwolf
Well-known Member
- Joined
- May 14, 2008
- Messages
- 1,216
- Office Version
- 2016
Hi Guys,
I got troubles with the following code wich I like to run from Access.
Could someone please look over this code and let me know what I need to change in order to correct instanciate to Excel from Access?
Manly I got problems where the code is ============================ marked.
But perhaps it would be good to look quickly over the code.
Many thanks
I got troubles with the following code wich I like to run from Access.
Could someone please look over this code and let me know what I need to change in order to correct instanciate to Excel from Access?
Manly I got problems where the code is ============================ marked.
But perhaps it would be good to look quickly over the code.
VBA Code:
Sub InsertWorksheetsFromFolder()
Dim appExcel As Excel.Application
Dim wkbExcel As Excel.Workbook
Dim strPath As String
Dim strFileName As String
Dim Bereich As Range
Dim strLC As String
Dim i As Integer
Set appExcel = New Excel.Application
Set wkbExcel = appExcel.Workbooks.Open("C:\Users\Silentwolf\Documents\My Data Projects\MyFiles\Test.xlsm")
appExcel.Visible = True
appExcel.Application.ScreenUpdating = False
strPath = "C:\Users\Silentwolf\Documents\Files\2019\Statements\"
strFileName = Dir(strPath & "*.xlsx")
Do While strFileName <> ""
appExcel.Workbooks.Open FileName:=strPath & strFileName, ReadOnly:=True
With appExcel.ActiveWorkbook
.Worksheets(1).Copy After:=wkbExcel.Sheets(1)
End With
appExcel.Workbooks(strFileName).Close
strFileName = Dir()
Loop
'=========================================================
For i = 2 To wkbExcel.Worksheets.count
With wkbExcel.Worksheets(i).UsedRange
strLC = .Cells(.Rows.count, .Columns.count).Address
Set Bereich = wkbExcel.Range("A2:" & strLC)
Bereich.Copy Destination:=Sheets("Zusammenfassung").Cells(Rows.count, 1).End(xlUp).Offset(1, 0)
End With
Next i
' =======================================================
appExcel.Application.ScreenUpdating = True
Stop
appExcel.Quit
Set wkbExcel = Nothing
Set appExcel = Nothing
End Sub