Good bives to all.
I need help to do a job with some files. I have a file, which is a template that should be loaded automatically thanks to a file chosen by the user. This file that is filled in will be a template that will upload the data to SAP.
The file uploaded by the user will be xls or csv.
I'm trying to create a macro that does the following:
Upload the file, choosing the user who wants,
Save this data in a two-dimensional Array, to later use it in the current style sheet (the template that the user will have open when they click on the macro).
Write the data to that file.
What I have done is:
Sub RellenarDoc()
'
' RellenarDoc Macro
' Rellenar el documento para subir los datos a SAP
'
Dim fd As Office.FileDialog
Dim FSO As Object, MyFile As Object
Dim FileName As String, Arr As Variant
'only allow the user to select one file
Application.FileDialog(msoFileDialogOpen).AllowMultiSelect = False
'make the file dialog visible to the user
intChoice = Application.FileDialog(msoFileDialogOpen).Show
'determine what choice the user made
If intChoice <> 0 Then
'get the file path selected by the user
strPath = Application.FileDialog( _
msoFileDialogOpen).SelectedItems(1)
End If
End Sub
It is a part of code that I found on the internet. The next thing I should do, as I say, is to save that data in an array and then for example get the array['A']['2'] (which is an identifier) to put it in the template file, sheet 1, position A2
Can someone help me?
It depends on what type of file the user selects (xls or csv) we will process the file in one way or another.
If it is an excel you can open the file, define the data range and load that range directly to an array to later use it wherever you want.
With a csv the process is different:
Then, once each file has been loaded in one way or another, you would have to process them and take that data to final excel.