問題の説明
セルに値が保存されているファイルを開く (Open files with values stored in cells)
Okay the title is a little ambiguous but what I'm trying to do is the following: I have a column of file names and I want to open them all using vba. I'm assuming it would be something like what I have below but I'm missing something. The number of files can change so I can't use a definite range.
For each cl in workbookC.worksheets("sheet1").range("A"). If cl.value <> "" then. Open (filename="cl.value"). End if. Next cl
リファレンスソリューション
方法 1:
The code below should work. Note that I would suggest not only making sure that the cell is not blank but also checking if the file exists using a FileSystemObject before attempting to opening.
Dim sourceWorksheet
Set sourceWorksheet = workbookC.Worksheets("sheet1")
Dim row
For row = 1 To 10 'rows containing filenames
If sourceWorksheet.Cells(row, 1).Value <> "" Then
Dim xlwb
Set xlwb = Workbooks.Open(sourceWorksheet.Cells(row, 1).Value)
'do stuff
xlwb.Close
End If
Next
(by Sean Connecticut、mr.Reband)