0

is there any way i can get the file name out of this statement? I'm trying to get the file name out of this statement so i can proceed with my coding..

Basically i'm trying to open multiple workbook and open multiple sheets to according to the workbook's name.

        strWorkbookNameAndPath = Application.GetOpenFilename _
       (FileFilter:=strFilt, _
        FilterIndex:=intFilterIndex, _
        Title:=strDialogueFileTitle, _
        MultiSelect:=True)

       fileArraySize = UBound(strWorkbookNameAndPath, 1) 
       nameArr = Split(strWorkbookNameAndPath, "\")
       strName = nameArr(UBound(nameArr))
       Worksheets.Add().Name = strName

       For i = 1 To fileArraySize

       Set wkbImportedWorkbook = Workbooks.Open(strWorkbookNameAndPath(i))
       Set wksImportedWorksheet = wkbImportedWorkbook.Sheets("Sheet1")
       With wksImportedWorksheet
       lrow = .Range("A" & .Rows.count).End(xlUp).Row
       Set rngImportCopyRange = .Range("A1:A" & lrow).EntireRow
       rngImportCopyRange.Copy
       wksMasterWorksheet.Range("A" & Rows.count).End(xlUp).Offset(1, 0).PasteSpecial        xlPasteValues
End With
wkbImportedWorkbook.Close
Set wkbImportedWorkbook = Nothing
Set wksImportedWorksheet = Nothing
Next i
pnuts
  • 58,317
  • 11
  • 87
  • 139
user2837847
  • 137
  • 1
  • 1
  • 15
  • 1
    Check: http://stackoverflow.com/questions/9086309/how-do-you-get-just-the-filename-rather-than-the-entire-file-path-of-an-open-fil – NoChance Nov 29 '13 at 08:12

1 Answers1

1

add this code:

dim nameArr
dim strName as string

nameArr = Split(strWorkbookNameAndPath, "\")
strName = nameArr(UBound(nameArr))

EDIT:

strWorkbookNameAndPath = Application.GetOpenFilename _
  (FileFilter:="", _
  FilterIndex:=0, _
  Title:="", _
  MultiSelect:=True)

fileArraySize = UBound(strWorkbookNameAndPath, 1)

For i = 1 To fileArraySize

  nameArr = Split(strWorkbookNameAndPath(i), "\")
  strName = nameArr(UBound(nameArr))
  Worksheets.Add().Name = strName

  Set wkbImportedWorkbook = Workbooks.Open(strWorkbookNameAndPath(i))
  Set wksImportedWorksheet = wkbImportedWorkbook.Sheets("Sheet1")
  With wksImportedWorksheet
    lrow = .Range("A" & .Rows.Count).End(xlUp).Row
    Set rngImportCopyRange = .Range("A1:A" & lrow).EntireRow
    rngImportCopyRange.Copy
    wksMasterWorksheet.Range("A" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
  End With
  wkbImportedWorkbook.Close
  Set wkbImportedWorkbook = Nothing
  Set wksImportedWorksheet = Nothing
Next i
Manuel Allenspach
  • 12,467
  • 14
  • 54
  • 76