silentwolf
Well-known Member
- Joined
- May 14, 2008
- Messages
- 1,216
- Office Version
- 2016
Hi guys,
sorry for the thread title but I haven't been able to think of a good one.
However here is where I am gettting stuck at.
At my previous posts I have been working on importing different worksheets into one and import this sheet into access.
What I got so far.
In Access I created a userform with a txtStatement(Textbox) and a btnBrowse(command button) and one btnTest(commandButton)
With fileDialog I am able to pickFolder where different excel workbook files are located.
The if statement I might could change a bit as it was from the code bevore where I picked a file...
You can let me know if there is a better way of doing this...
The above code works fine it opens the workbook and then run Code from that specific workbook with the xl.Run "InsertStatementsFromFolderPath" strFolderPath procedure
So so far the code is working fine and I am opening the workbook where all workbooks within the folder got inserted into ThisWorkbook in the first Position. Only one worksheet is in that workbook!
So far so good. However this is not quite finished yet.
I like to insert this worksheet in the access database. So how should I go about it? How to I get the worksheet into my access Form so when I am using the btnTest_click event to do that for me.
How am I able to create a varible so Access knows what to import.
It is most proberbly easy but I am running in circles at the moment .
Hope you guys understand what I am after and just can put me on the right track.
Many thanks
sorry for the thread title but I haven't been able to think of a good one.
However here is where I am gettting stuck at.
At my previous posts I have been working on importing different worksheets into one and import this sheet into access.
What I got so far.
In Access I created a userform with a txtStatement(Textbox) and a btnBrowse(command button) and one btnTest(commandButton)
With fileDialog I am able to pickFolder where different excel workbook files are located.
Code:
Private Sub btnBrowse_Click()
Dim diag As Office.FileDialog
Dim item As Variant
Set diag = Application.FileDialog(msoFileDialogFolderPicker) 'Folder Picker
With diag
.AllowMultiSelect = False
.Title = "Wählen Sie den Folder aus!"
.InitialFileName = p_cstrCSV_Verzeichnis 'public const_FilePath
If diag.Show And .SelectedItems.count > 0 Then
Me.txtStatement.Value = .SelectedItems.item(1)
End If
End With
Set diag = Nothing
End Sub
The if statement I might could change a bit as it was from the code bevore where I picked a file...
You can let me know if there is a better way of doing this...
VBA Code:
Private Sub btnTest_Click()
Dim xl As Excel.Application
Dim wkbExcel As Excel.Workbook
Dim strFolderPath As String
Set xl = CreateObject("Excel.Application")
xl.Workbooks.Open "C:\Users\Documents\My Data Projects\Auszugsklasse\AJL_Statement.xlsm", True, False
strFolderPath = Me.txtStatement.Value
strFolderPath = strFolderPath & "\"
'-------------------------------------------------------------------
xl.Run "InsertStatementsFromFolderPath", strFolderPath
xl.Visible = True
Set xl = Nothing
End Sub
The above code works fine it opens the workbook and then run Code from that specific workbook with the xl.Run "InsertStatementsFromFolderPath" strFolderPath procedure
So so far the code is working fine and I am opening the workbook where all workbooks within the folder got inserted into ThisWorkbook in the first Position. Only one worksheet is in that workbook!
So far so good. However this is not quite finished yet.
I like to insert this worksheet in the access database. So how should I go about it? How to I get the worksheet into my access Form so when I am using the btnTest_click event to do that for me.
How am I able to create a varible so Access knows what to import.
It is most proberbly easy but I am running in circles at the moment .
Hope you guys understand what I am after and just can put me on the right track.
Many thanks