Hi all,
Full disclosure, I am still learning VBA, am not very good yet, and hoping someone can help. I currently have a script (not written by myself) being used at my office. It used to run fine but now is throwing an error because it is picking up a file called "thumbs.db". After some due diligence, it seems that this file is a "hidden" file which we have no idea why it is now present. Regardless, I'm trying to rearrange a loop in a script to essentially skip this file / file type. Basically the script is meant to do the following (simple):
Goes to a specific path, loops through and opens all the excel files and pulls data into another sheet.
This is what the script looks like currently (original):
Sub Logging(path As String, newpath As String)
Dim objFile As Variant
Dim myFolder
Dim strFileName As String
Dim myDir As String
Dim strFilePath As String
Dim rownum As Integer
'myDir = InputBox(prompt:="Input file path")
rownum = 1895
'InputBox(prompt:="Input row number with formula")
Set FileSys = CreateObject("Scripting.FileSystemObject")
Set myFolder = FileSys.GetFolder(path)
For Each objFile In myFolder.Files
strFileName = objFile.Name
strFilePath = objFile.path
MsgBox objFile.path
Log strFilePath, strFileName, rownum, FileDateTime(strFilePath)
Name strFilePath As newpath & "" & strFileName
Next objFile
End Sub
This was my attempt at fixing and skipping hidden files (throws debug error):
Sub Logging(path As String, newpath As String)
Dim objFile As Variant
Dim myFolder
Dim strFileName As String
Dim myDir As String
Dim strFilePath As String
Dim rownum As Integer
'myDir = InputBox(prompt:="Input file path")
rownum = 1895
'InputBox(prompt:="Input row number with formula")
Set FileSys = CreateObject("Scripting.FileSystemObject")
Set myFolder = FileSys.GetFolder(path)
For Each objFile In myFolder.Files
If file.Attributes.tostring <> "Hidden, System" Then
strFileName = objFile.Name
strFilePath = objFile.path
Log strFilePath, strFileName, rownum, FileDateTime(strFilePath)
Name strFilePath As newpath & "" & strFileName
Else
End If
Next objFile
End Sub
Any assistance is greatly appreciated as both attempts throw errors.
Full disclosure, I am still learning VBA, am not very good yet, and hoping someone can help. I currently have a script (not written by myself) being used at my office. It used to run fine but now is throwing an error because it is picking up a file called "thumbs.db". After some due diligence, it seems that this file is a "hidden" file which we have no idea why it is now present. Regardless, I'm trying to rearrange a loop in a script to essentially skip this file / file type. Basically the script is meant to do the following (simple):
Goes to a specific path, loops through and opens all the excel files and pulls data into another sheet.
This is what the script looks like currently (original):
Sub Logging(path As String, newpath As String)
Dim objFile As Variant
Dim myFolder
Dim strFileName As String
Dim myDir As String
Dim strFilePath As String
Dim rownum As Integer
'myDir = InputBox(prompt:="Input file path")
rownum = 1895
'InputBox(prompt:="Input row number with formula")
Set FileSys = CreateObject("Scripting.FileSystemObject")
Set myFolder = FileSys.GetFolder(path)
For Each objFile In myFolder.Files
strFileName = objFile.Name
strFilePath = objFile.path
MsgBox objFile.path
Log strFilePath, strFileName, rownum, FileDateTime(strFilePath)
Name strFilePath As newpath & "" & strFileName
Next objFile
End Sub
This was my attempt at fixing and skipping hidden files (throws debug error):
Sub Logging(path As String, newpath As String)
Dim objFile As Variant
Dim myFolder
Dim strFileName As String
Dim myDir As String
Dim strFilePath As String
Dim rownum As Integer
'myDir = InputBox(prompt:="Input file path")
rownum = 1895
'InputBox(prompt:="Input row number with formula")
Set FileSys = CreateObject("Scripting.FileSystemObject")
Set myFolder = FileSys.GetFolder(path)
For Each objFile In myFolder.Files
If file.Attributes.tostring <> "Hidden, System" Then
strFileName = objFile.Name
strFilePath = objFile.path
Log strFilePath, strFileName, rownum, FileDateTime(strFilePath)
Name strFilePath As newpath & "" & strFileName
Else
End If
Next objFile
End Sub
Any assistance is greatly appreciated as both attempts throw errors.