C
chantal.lyn
I need to import an unspecified number of text files (converted from
Word to trap the formfield contents) into Access, however I need to
rename a number of the filenames to strip "."
I'm using code I found elsewhere on here, however whenever the loop
tries to rename a file, I get error message 53 'File not found'. The
file is very much there, and checking the variable contents in the
immediate window produces the right results.
Can anyone suggest why this **** code isn't working? Thanks!
-----------------------------------------------
Sub RemovePunctuation()
'On Error Resume Next
Dim strFolder As String
Dim strFileName As String
Dim strNewName As String
strFolder = "C:\Documents and Settings\CGUEVARA\My
Documents\doc\3ps\converted"
strFileName = Dir(strFolder & "\*.txt")
Do Until Len(strFileName) = 0
' Only rename the ones with embedded periods.
If strFileName Like "*.*.*" Then
' strip off the ".txt" to get new name
strNewName = Left(strFileName, Len(strFileName) - 4)
' remove any embedded periods (.)
strNewName = Replace(strNewName, ".", "")
strNewName = Replace(strNewName, ",", "")
strNewName = Replace(strNewName, " ", "")
' Rename the file.
Name strFileName As strNewName & ".txt"
'End If
' Get next file name.
strFileName = Dir()
Loop
MsgBox "Filenames fixed!", vbInformation, "Done now"
End Sub
Word to trap the formfield contents) into Access, however I need to
rename a number of the filenames to strip "."
I'm using code I found elsewhere on here, however whenever the loop
tries to rename a file, I get error message 53 'File not found'. The
file is very much there, and checking the variable contents in the
immediate window produces the right results.
Can anyone suggest why this **** code isn't working? Thanks!
-----------------------------------------------
Sub RemovePunctuation()
'On Error Resume Next
Dim strFolder As String
Dim strFileName As String
Dim strNewName As String
strFolder = "C:\Documents and Settings\CGUEVARA\My
Documents\doc\3ps\converted"
strFileName = Dir(strFolder & "\*.txt")
Do Until Len(strFileName) = 0
' Only rename the ones with embedded periods.
If strFileName Like "*.*.*" Then
' strip off the ".txt" to get new name
strNewName = Left(strFileName, Len(strFileName) - 4)
' remove any embedded periods (.)
strNewName = Replace(strNewName, ".", "")
strNewName = Replace(strNewName, ",", "")
strNewName = Replace(strNewName, " ", "")
' Rename the file.
Name strFileName As strNewName & ".txt"
'End If
' Get next file name.
strFileName = Dir()
Loop
MsgBox "Filenames fixed!", vbInformation, "Done now"
End Sub