How to open files from excel list using VBA?

badsham77

New Member
Joined
May 4, 2011
Messages
10
I need some help with this coding. I want to open files from an excel list.

Sub Openfile()

Dim wkbOne as Workbook

Set wkbOne = Application.Workbooks.Open(Filename:=Worksheets("Sheet1").Range("A1") & Worksheets("Sheet1").Range("B1")
'where "A1" is the path where the file located and "B1" is the file name.'
End Sub

When I run this it will work, but if I change to below it won't open all file in range, what's wrong with this?

Sub Openfile()

Dim wkbOne as Workbook

Set wkbOne = Application.Workbooks.Open(Filename:=Worksheets("Sheet1").Range("A1:A10") & Worksheets("Sheet1").Range("B1:B10")

End Sub

Thanks for the help.
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Try

Code:
Sub Openfile()
Dim wkbOne As Workbook, i As Long, j As Long
With ThisWorkbook
    For i = 1 To 10
        If .Worksheets("Sheet1").Range("A" & i).Value <> "" And .Worksheets("Sheet1").Range("B" & i).Value <> "" Then
            j = j + 1
            Set wkbOne = Workbooks.Open(.Worksheets("Sheet1").Range("A" & i).Value & .Worksheets("Sheet1").Range("B" & i).Value)
            Application.DisplayAlerts = False
            wkbOne.SaveAs Filename:=.Worksheets("Sheet1").Range("A" & i).Value & .Worksheets("Sheet1").Range("B" & i).Value, Password:=.Worksheets("Sheet1").Range("C" & i).Value
            wkbOne.Close True
            Application.DisplayAlerts = True
        End If
    Next i
End With
MsgBox j & "files opened", vbInformation
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,835
Messages
6,127,169
Members
449,368
Latest member
JayHo

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