bigcupoftea
New Member
- Joined
- Oct 26, 2023
- Messages
- 1
- Office Version
- 365
- Platform
- Windows
Hi all, I'm fairly new to VBA beyond a little tinkering here and there.
I'd like to import multiple text files into a new workbook with each file on a new sheet. I found this code on another thread but this seems to be coded to import the sheets into the current workbook. I've tried changing <Set desWB> to "NewWorkbook" but that doesn't appear to be the answer. Could someone please point me in the right direction? Thanks.
I'd like to import multiple text files into a new workbook with each file on a new sheet. I found this code on another thread but this seems to be coded to import the sheets into the current workbook. I've tried changing <Set desWB> to "NewWorkbook" but that doesn't appear to be the answer. Could someone please point me in the right direction? Thanks.
VBA Code:
Sub CopySheets()
Application.ScreenUpdating = False
Dim fd As FileDialog, lRow As Long, vSelectedItem As Variant, srcWB As Workbook, desWB As Workbook
Set desWB = ThisWorkbook
Set fd = Application.FileDialog(msoFileDialogFilePicker)
With fd
.AllowMultiSelect = True
If .Show = -1 Then
For Each vSelectedItem In .SelectedItems
Set srcWB = Workbooks.Open(vSelectedItem)
Sheets(1).Copy after:=desWB.Sheets(desWB.Sheets.Count)
srcWB.Close False
Next
Else
End If
End With
Application.ScreenUpdating = True
End Sub