Hello –
Our team has been using an xls Marco to retrieve the files in a specific path provided by the user. There is a button on the sheet that runs the below Marco. This has been working perfectly for years however the new ask is for the Marco to return the image dimensions (as in 2189 x 1700) of the file if this information exists into column J of each row.
I have searched the web and this forum and have not been able to find something to add to this code to make this work.
Any advice on this would be very much appreciated.
Thanks for your help,
Cindy
Our team has been using an xls Marco to retrieve the files in a specific path provided by the user. There is a button on the sheet that runs the below Marco. This has been working perfectly for years however the new ask is for the Marco to return the image dimensions (as in 2189 x 1700) of the file if this information exists into column J of each row.
I have searched the web and this forum and have not been able to find something to add to this code to make this work.
Any advice on this would be very much appreciated.
Thanks for your help,
Cindy
Code:
Public gFileTypes As String
Public gCurrentRow As Integer
Public gCurrentIndent As Integer
Public gFileCount As Integer
Public gFolderCount As Integer
Public gGlobalPath As String
Public fs As Object
Sub GetFiles()
Application.Cursor = xlWait
Application.ScreenUpdating = False
Call CleanUp
' Application.ScreenUpdating = True
gFileCount = 0
gFolderCount = 0
Set fs = CreateObject("Scripting.FileSystemObject")
' Determine files to look for
' -------------------------------------------------------------------
FileTypes = Range("FileTypes")
FileTypes = Replace(FileTypes, " ", "")
gFileTypes = FileTypes
' Clean up FolderName
' ------------------------------------------------------------------
folderName = Range("FilePath")
folderName = Replace(folderName, "/", "\")
If Right(folderName, 1) = "\" Then folderName = Left(folderName, Len(folderName) - 1)
Range("FilePath") = folderName
gCurrentRow = 22
gCurrentIndent = 0
gGlobalPath = folderName
Call DoFolder(gGlobalPath)
Application.ScreenUpdating = False
Call IndentRows
Application.ScreenUpdating = True
Range("files") = gFileCount
Range("folders") = gFolderCount
Range("A24").Select
Application.Cursor = xlDefault
Application.StatusBar = ""
ActiveWindow.ScrollRow = 24
'Worksheets("PivotTable").PivotTables("PivotTable1").PivotCache.Refresh
Range("D" & CStr(CurrentRow) & ":" & "G" & CStr(CurrentRow)).Font.Name = "Arial"
Range("D" & CStr(CurrentRow) & ":" & "G" & CStr(CurrentRow)).Font.Size = "8"
Range("D" & CStr(CurrentRow) & ":" & "G" & CStr(CurrentRow)).HorizontalAlignment = xlLeft
MsgBox "Finished searching. Scroll up to adjust settings" & Chr(13) & "or to search again.", vbOKOnly, "Done"
End Sub
Sub DoFolder(folderPath As String)
gFolderCount = gFolderCount + 1
Set folder = fs.GetFolder(folderPath)
Set foldercontents = folder.Files
For Each fileObject In foldercontents
Filename = fileObject.Name
Application.StatusBar = Filename
' Is this file what we're looking for?
Extension = Right(Filename, 3)
If InStr(Range("FileTypes"), Extension) <> 0 Or Range("FileTypes") = "*.*" Then
gFileCount = gFileCount + 1
With Range("C" & CStr(gCurrentRow))
.Value = Filename
.Select
'Selection.InsertIndent gCurrentIndent + 1
End With
AbsolutePath = fileObject.Path
RelativePath = Right(AbsolutePath, Len(AbsolutePath) - Len(gGlobalPath) - 1)
Range("D" & CStr(gCurrentRow)).Value = AbsolutePath
Range("E" & CStr(gCurrentRow)).Value = AbsolutePath
Range("F" & CStr(gCurrentRow)).Value = fileObject.Size
DateCreated = fileObject.DateCreated
Range("G" & CStr(gCurrentRow)).Value = FormatDateTime(DateCreated, vbShortDate)
DateModified = fileObject.DateLastModified
Range("H" & CStr(gCurrentRow)).Value = FormatDateTime(DateModified, vbShortDate)
Range("I" & CStr(gCurrentRow)).Value = fileObject.Type
gCurrentRow = gCurrentRow + 1
End If
Next
Set newFolderCollection = folder.subfolders
For Each newFolder In newFolderCollection
gCurrentIndent = gCurrentIndent + 1
filePath = newFolder.Name
With Range("C" & CStr(gCurrentRow))
.Value = UCase(filePath)
.Font.FontStyle = "Bold"
.Select
'Selection.InsertIndent gCurrentIndent
gCurrentRow = gCurrentRow + 1
End With
DoFolder (folderPath & "/" & filePath)
gCurrentIndent = gCurrentIndent - 1
Next
End Sub
Sub CleanUp()
Application.StatusBar = "Cleaning up..."
CurrentCursor = Application.Cursor
CurrentScreen = Application.ScreenUpdating
Application.ScreenUpdating = False
Application.Cursor = xlWait
CurrentRow = 25
While Range("C" & CStr(CurrentRow)).Value <> ""
Worksheets("Results").Rows(CurrentRow).Delete
Wend
CurrentRow = 2
'While Range("PivotData!A" & CStr(CurrentRow)).Value <> ""
' Worksheets("PivotData").Rows(CurrentRow).Delete
'Wend
Application.StatusBar = ""
Application.ScreenUpdating = CurrentScreen
Application.Cursor = CurrentCursor
End Sub
Sub IndentRows()
CurrentRow = 25
While Range("C" & CStr(CurrentRow)).Value <> ""
RowValue = CurrentRow
'LevelValue = Range("C" & CStr(CurrentRow)).IndentLevel
With Worksheets("Results")
For i = 2 To LevelValue
.Rows(CStr(RowValue)).Group
Next
End With
CurrentRow = CurrentRow + 1
Wend
ActiveSheet.Outline.ShowLevels RowLevels:=1
End Sub
Sub RevertLinksToURLs()
CurrentRow = 22
Dim HL As Object
Application.Cursor = xlWait
Application.ScreenUpdating = False
While Range("C" & CStr(CurrentRow)).Value <> ""
NumberOfLinks = Range("E" & CStr(CurrentRow)).Hyperlinks.Count
If NumberOfLinks > 0 Then
Set HL = Range("E" & CStr(CurrentRow)).Hyperlinks(1)
Address = HL.Address
HL.Delete
Range("E" & CStr(CurrentRow)).Value = Address
Range("E" & CStr(CurrentRow) & ":" & "E" & CStr(CurrentRow)).Font.Name = "Arial"
Range("E" & CStr(CurrentRow) & ":" & "E" & CStr(CurrentRow)).Font.Size = "8"
Range("E" & CStr(CurrentRow) & ":" & "E" & CStr(CurrentRow)).HorizontalAlignment = xlLeft
End If
CurrentRow = CurrentRow + 1
Wend
Application.Cursor = xlDefault
End Sub
Sub RevertURLstoLinks()
CurrentRow = 22
Application.Cursor = xlWait
Application.ScreenUpdating = False
While Range("C" & CStr(CurrentRow)).Value <> ""
If Range("E" & CStr(CurrentRow)).Value <> "" Then
Range("E" & CStr(CurrentRow)).Select
ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:= _
Range("E" & CStr(CurrentRow)), TextToDisplay:="Link"
End If
CurrentRow = CurrentRow + 1
Wend
Application.Cursor = xlDefault
End Sub