Import VBA assistance

skinny220

New Member
Joined
Jan 10, 2015
Messages
34
All,

Does anyone know a VBA that will import three files (Inventory.xlxs, Serial Number.xlsx, Quote.xlsx.) all files are in a folder I have labeled Data Import?

Skinny (Carter)
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
.
.

Perhaps something like this:

Code:
Sub ImportData()
  Const strDIR As String = "C:\Data Import\"
  Dim varFnames As Variant
  Dim wbkSource As Workbook
  Dim wbkDestin As Workbook
  Dim intWIndex As Integer
  Dim wksSource As Worksheet
  
  varFnames = Array("Inventory.xlsx", "Serial Number.xlsx", "Quote.xlsx")
  Application.DisplayAlerts = False
  Set wbkDestin = Workbooks.Add
  For intWIndex = LBound(varFnames) To UBound(varFnames)
    If Dir$(strDIR & varFnames(intWIndex)) <> vbNullString Then
      Set wbkSource = Workbooks.Open(strDIR & varFnames(intWIndex))
      For Each wksSource In wbkSource.Worksheets
        wksSource.UsedRange.Copy
        With wbkDestin.Sheets(Sheets.Count)
          .Range("A1").PasteSpecial xlPasteValuesAndNumberFormats
          .Name = Split(wbkSource.Name, ".")(0) & Chr$(95) & wksSource.Index
        End With
        wbkDestin.Sheets.Add
      Next wksSource
      wbkSource.Close False
    End If
  Next intWIndex
  Application.DisplayAlerts = True
      
End Sub
 
Upvote 0
skinny220:

You posted in the Access forum. Were you looking to import the Excel files into Access?
 
Upvote 0

Forum statistics

Threads
1,221,907
Messages
6,162,777
Members
451,788
Latest member
Hideoshie

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