Obtaining Values from Filenames

  • Thread starter Thread starter DLinkage
  • Start date Start date
Click For Summary
SUMMARY

This discussion focuses on extracting specific numeric values from filenames using Visual Basic for Applications (VBA). The example provided demonstrates how to retrieve the numbers "12" and "13" from the filenames "ABC12X.txt" and "ABC13X.txt" respectively, utilizing the Mid function. The code snippet shows how to implement this extraction effectively. Additionally, resources such as the Excel string manipulation guide and the Office Development forum are recommended for further assistance.

PREREQUISITES
  • Basic understanding of Visual Basic for Applications (VBA)
  • Familiarity with Excel functions, specifically the Mid function
  • Knowledge of string manipulation techniques in programming
  • Access to Excel for testing VBA code
NEXT STEPS
  • Explore advanced string manipulation techniques in VBA
  • Learn about error handling in VBA for file operations
  • Investigate the use of regular expressions in VBA for complex filename patterns
  • Review additional resources on VBA programming in Excel
USEFUL FOR

This discussion is beneficial for Excel users, VBA developers, and anyone looking to automate data extraction from filenames within spreadsheets.

DLinkage
Messages
17
Reaction score
0
I'm trying to read in a file's filename and append part of the filename to a certain range of cells. This is to say if the filename was "ABC12X.txt"
and another filename was "ABC13X.txt", then how could I obtain the values "12" and "13" given the filename information alone? Thanks
 
Technology news on Phys.org
Do some string manipulations i guess...I forgot my vb :(
 
DLinkage said:
I'm trying to read in a file's filename and append part of the filename to a certain range of cells. This is to say if the filename was "ABC12X.txt"
and another filename was "ABC13X.txt", then how could I obtain the values "12" and "13" given the filename information alone? Thanks

If what you are trying to extract is always the 4th-5th characters, you can use the mid function:

Sub test()
Dim s1 As String
s1 = "ABC12X.txt"
Debug.Print Mid(s1, 4, 2) 'result is 12
End Sub


If you need addition help, the 'Office Development' forum within the following VB forum is great:

http://www.vbforums.com/index.php

Good luck. :smile:
 
Last edited:

Similar threads

  • · Replies 10 ·
Replies
10
Views
2K
  • · Replies 2 ·
Replies
2
Views
6K
  • · Replies 18 ·
Replies
18
Views
6K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 4 ·
Replies
4
Views
9K
  • · Replies 6 ·
Replies
6
Views
5K
Replies
4
Views
3K
  • · Replies 4 ·
Replies
4
Views
4K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 3 ·
Replies
3
Views
5K