Import automatically data from 2 workbooks and keep source formatting

bseignot

New Member
Joined
Nov 16, 2016
Messages
2
Hello there,

I have a folder containing 3 files : my Excel file (with my macro), Book1 and Book2.

I would like to create a macro to import automatically my two ".xlsx" files (Book1 and Book2) in my Excel file.
Data from Book1.xlsx would be placed in Sheet1 and Book2.xlsx in Sheet2. I also want to keep the source formatting (from Book1 and Book2).
Book1 and Book2 are always placed in the same folder as my Excel file.
I would like to use this macro in different folders, always containing my Excel file, Book1 and Book2, I guess the macro has to detect Book1 and Book2 using the pathname of my Excel file.

If anyone could give some help that would be great.

Thanks
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
I use a file or folder selector for dynamic purposes. Helps for when I share a macro with someone too.

Excel version? If you have 2016, you have Get&Transform which makes the process for static file/folder location easier. While I've done some macros to import and parse report data, Get&Transform is going to bring that to faster development without all the coding or VBA in/security.
 
Upvote 0
This is the code snippet I use in macro to select files and begin the parsing loop that goes through each file. I use this to work with 10kb to 500kb files and selecting as many as 300-400. though usually only 25-30 files.
Code:
MsgBox "Please select the appropriate TXT files for evaluation:" & vbCrLf & _
    "Select multiple files to be imported." & vbCrLf & _
    "(From the Same Folder)" & vbCrLf & _
    "Use SHIFT or CTRL to select multiple Files at once." & vbCrLf & vbCrLf & _
    "", vbInformation, ""
Set fd = Application.FileDialog(msoFileDialogFilePicker)
With fd
    .Filters.Clear
    .Filters.Add ".txt Files", "*.txt"
    .AllowMultiSelect = True
If .Show = -1 Then
For Each VRTSelectedItem In .SelectedItems
' MsgBox "Processing file: " & vrtSelectedItem
Next
Else
Stop
End If
Application.ScreenUpdating = False
For Each VRTSelectedItem In .SelectedItems
......
Next
 
Upvote 0

Forum statistics

Threads
1,216,037
Messages
6,128,442
Members
449,453
Latest member
jayeshw

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top