I need help, I found some VBA from an excel workbook that I want to be able to use in access. It currently works fine from the excel workbook but I need to use it in access. I have no experience with VBA in Access and I can only think the same code can be used but needs to be tweaked for access. The code looks for information inside files in a folder and renames the files based on the value found at a certain position in the file. It also adds he extension ".txt". Can anyone help make this code work in access?
Thank you
Code:
Function RenameTextFiles()
Dim fso As FileSystemObject
Dim x As Integer
Dim strPortCode As String
Dim strfile As String
Dim TextLine
Dim strFullFileName As String
Dim FILEPATH As String
Dim FILEPATH2 As String
FILEPATH = "C:\Data\"
FILEPATH2 = "C:\TempFiles\"
Dim pathcrnt As String, batch file As Integer
pathcrnt = ActiveWorkbook.Path
batch_file = FreeFile()
Set fso = CreateObject("Scripting.FileSystemObject")
strfile = Dir(FILEPATH)
Do While strfile <> ""
x = 1
strFullFileName = FILEPATH & strfile
Open strFullFileName For Input As #1 ' Open file.
Do While Not EOF(1) ' Loop until end of file.
Line Input #1, TextLine ' Read line into variable.
If x = 48 Then
strPortCode = Mid(TextLine, 18, 4)
Exit Do
End If
x = x + 1
Loop
Close #1 ' Close file.
If Left(fso.GetFileName(strfile), 5) = "PCOSS" Then
If Not fso.FileExists(FILEPATH & "COSS" & strPortCode & ".txt") Then
Name FILEPATH & strfile As FILEPATH & "COSS" & strPortCode & ".txt"
End If
End If
strfile = Dir
Loop
End Function