title: Anyway to only copy part of the file name into excel with macros?
body: <p>I've saw a few post related to this question but the answer provided couldn't help me at all. For example my file name is "SPC_PLTB_450B_05092017_25°C_CW",how am I going to <strong>only copy the date</strong> in the file name and <strong>paste it into my main workbook</strong> using macros ? My macros will find the next empty cell in Column C and paste the date of the filename in it.</p>
  
  <p><a href="https://i.stack.imgur.com/rUZIM.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/rUZIM.png" alt="What my main workbook looks like"></a>
  This is the macros I have now. Where can I insert the required code ? Thank you in advance.
      Sub trial()</p>
  
  <pre><code>Dim wb As Workbook, wb2 As Workbook, wb3 As Workbook
  Dim ws As Worksheet
  
  Dim fn As String
  
  Set wb = ActiveWorkbook
  
  'this is for the excel to add one more worksheet for the raw data
  Set ws = Sheets.Add(After:=Sheets(Worksheets.Count))
  Dim Ret
  
  'this whole part is for importing the raw data files into excel
      Ret = Application.GetOpenFilename("Lkl Files (*.lkl), *.lkl")
  
      If Ret &lt;&gt; False Then
          With ActiveSheet.QueryTables.Add(Connection:= _
          "TEXT;" &amp; Ret, Destination:=Range("$A$1"))
          .Name = "SPC_PLTB_450B_12092107_25°C_CW"
          .FieldNames = True
          .RowNumbers = False
          .FillAdjacentFormulas = False
          .PreserveFormatting = True
          .RefreshOnFileOpen = False
          .RefreshStyle = xlInsertDeleteCells
          .SavePassword = False
          .SaveData = True
          .AdjustColumnWidth = True
          .RefreshPeriod = 0
          .TextFilePromptOnRefresh = False
          .TextFilePlatform = 65001
          .TextFileStartRow = 1
          .TextFileParseType = xlDelimited
          .TextFileTextQualifier = xlTextQualifierDoubleQuote
          .TextFileConsecutiveDelimiter = False
          .TextFileTabDelimiter = True
          .TextFileSemicolonDelimiter = False
          .TextFileCommaDelimiter = False
          .TextFileSpaceDelimiter = False
          .TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
          .TextFileDecimalSeparator = ","
          .TextFileThousandsSeparator = "."
          .TextFileTrailingMinusNumbers = True
          .Refresh BackgroundQuery:=False
  
          End With
      End If
  
  
      Sheets(2).Activate
  
      'this is to search for the next empty cell and put the date
      Dim FirstCell As String
          Dim i As Integer
              FirstCell = "C19"
              Range(FirstCell).Select
              Do Until ActiveCell.Value = ""
              If ActiveCell.Value = "" Then
              Exit Do
              Else
              ActiveCell.Offset(1, 0).Select
              End If
              Loop
              ActiveCell = Format(Date, "mm/dd/yyyy")
  
      'this is to filter the raw data into the desired value
      ws.Activate
      ws.AutoFilterMode = False
  
      'change the value of Criteria1 between "" into the desired value for filtering
      ws.Range("$A$9:$P$417").AutoFilter Field:=5, Criteria1:= _
          "1"
  
      Range("F31:F401").Select
      Selection.Copy
  
  
  
      Sheets(2).Activate
  
  
      'this is for the raw data to be copied into each worksheet
  
              FirstCell = "D19"
              Range(FirstCell).Select
              Do Until ActiveCell.Value = ""
              If ActiveCell.Value = "" Then
              Exit Do
              Else
              ActiveCell.Offset(1, 0).Select
              End If
              Loop
  
  
      Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
          False, Transpose:=True
  
     Sheets(3).Activate
      FirstCell = "C19"
              Range(FirstCell).Select
              Do Until ActiveCell.Value = ""
              If ActiveCell.Value = "" Then
              Exit Do
              Else
              ActiveCell.Offset(1, 0).Select
              End If
              Loop
              ActiveCell = Format(Date, "mm/dd/yyyy")
  
      ws.Activate
  
      Range("D31:D401").Select
      Application.CutCopyMode = False
      Selection.Copy
  
  
      Sheets(3).Activate
              FirstCell = "D19"
              Range(FirstCell).Select
              Do Until ActiveCell.Value = ""
              If ActiveCell.Value = "" Then
              Exit Do
              Else
              ActiveCell.Offset(1, 0).Select
              End If
              Loop
  
  
      Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
          False, Transpose:=True
  
          Sheets(4).Activate
      FirstCell = "C19"
              Range(FirstCell).Select
              Do Until ActiveCell.Value = ""
              If ActiveCell.Value = "" Then
              Exit Do
              Else
              ActiveCell.Offset(1, 0).Select
              End If
              Loop
              ActiveCell = Format(Date, "mm/dd/yyyy")
  
      ws.Activate
  
      Range("G31:G401").Select
      Application.CutCopyMode = False
      Selection.Copy
  
  
  
      Sheets(4).Activate
      FirstCell = "D19"
              Range(FirstCell).Select
              Do Until ActiveCell.Value = ""
              If ActiveCell.Value = "" Then
              Exit Do
              Else
              ActiveCell.Offset(1, 0).Select
              End If
              Loop
  
  
      Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
          False, Transpose:=True
  
  With ActiveWorkbook
      .Worksheets(.Worksheets.Count).Delete
      End With
  
  End Sub
  </code></pre>