Log in

View Full Version : List selected filenames in an Excel range of cells



TomyLee
09-24-2012, 02:24 AM
Hi,

How can I write the message in cell A2


Code:
Msg = "You selected:" & vbNewLine
For I = LBound(FileNames) To UBound(FileNames)
Msg = Msg & FileNames(I) & vbNewLine
Next I
MsgBox Msg
[/code]

I my VBA code I can select many files, and I need to write in some cells starting with A12

Thank you.

princ_wns
09-24-2012, 04:07 PM
Hi Tomylee,

Please use this i hope this will help you.


Public Sub GetBrandsFiles()
Dim varArrFile As Variant
Dim intCtr As Integer
Dim strFiles As String
Dim rngFiles As Range

With ThisWorkbook.Worksheets("Sheet2")
Set rng = .Range("A1")
varArrFile = Application.GetOpenFilename("*.xls,*.xlsx", , "Select Brands Files", , True)
If IsArray(varArrFile) = False Then
MsgBox "Please Select Brand File..."
shtIndex.Range("rngBrand1").Value = ""
Exit Sub
Else
rng.Offset(0, 1).Value = "Following Files have selected by you :"
For intCtr = LBound(varArrFile) To UBound(varArrFile)
rng.Offset(intCtr, 1).Value = varArrFile(intCtr)
Next
End If
End With
End Sub


Regards
Prince

TomyLee
09-24-2012, 06:24 PM
Hi Prince,

Thank you very much. It's all I need.
Once again thank you.