Grizlore
Active Member
- Joined
- Aug 22, 2006
- Messages
- 259
Although this code works great, it takes an age (+50mins) to run.
Could anyone have a look and see if this code can be speeded up anywhere please?
Any help would be appreciated
Thanks for looking
Could anyone have a look and see if this code can be speeded up anywhere please?
Any help would be appreciated
Code:
Sub Button()
Application.ScreenUpdating = False
Dim TheFolder As String
Dim TheFile As String
Dim TheHyperlinkPath As String
Dim TheRow As Integer
Dim CreationDate As Date
TheRow = 2
TheFolder = "\\WWW0\WWWSHARE\GMP\Quality and Hygiene\CofAs"
TheFile = Dir(TheFolder & "\*.*")
Sheets("All the CofAs").Select
Range("A2").Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.ClearContents
Range("A2").Select
Do Until TheFile = ""
TheHyperlinkPath = TheFolder & "\" & TheFile
Sheets("All the CofAs").Cells(TheRow, 1).Select
Sheets("All the CofAs").Hyperlinks.Add Anchor:=Cells(TheRow, 1), Address:= _
TheHyperlinkPath, TextToDisplay:=TheFile
ActiveCell.Offset(0, 1).Activate
ActiveCell = FileDateTime(TheHyperlinkPath)
TheRow = TheRow + 1
TheFile = Dir
Loop
With Sheets("All the CofAs")
With .Columns("A")
.AutoFilter Field:=1, Criteria1:="Certificates Of Analysis.xls"
On Error Resume Next
.SpecialCells(xlCellTypeVisible).EntireRow.Delete
On Error GoTo 0
End With
End With
Rows("1:1").Select
Selection.Insert Shift:=xlDown
Range("A1").Select
ActiveCell.FormulaR1C1 = "Certificate of Analysis File Name"
Range("B1").Select
ActiveCell.FormulaR1C1 = "File Date"
Rows("1:1").Select
Selection.Font.Bold = True
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.ShrinkToFit = False
.MergeCells = False
End With
Range("B2").Select
Selection.Sort Key1:=Range("B2"), Order1:=xlDescending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
Columns("B:B").Select
Selection.Insert Shift:=xlToRight
Columns("A:A").Select
Selection.TextToColumns Destination:=Range("A1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, _
Semicolon:=False, Comma:=False, Space:=False, Other:=True, OtherChar _
:=".", FieldInfo:=Array(Array(1, 1), Array(2, 1)), TrailingMinusNumbers:=True
Range("B1").Select
ActiveCell.FormulaR1C1 = "File Type"
Range("C9").Select
Columns("B:C").EntireColumn.AutoFit
Columns("B:C").Select
Selection.Font.Underline = xlUnderlineStyleSingle
Selection.Font.Underline = xlUnderlineStyleNone
Selection.Font.ColorIndex = 1
Columns("B:C").EntireColumn.AutoFit
Selection.ColumnWidth = 12.5
Columns("C:C").Select
Columns("C:C").EntireColumn.AutoFit
Columns("B:B").Select
With Selection
.HorizontalAlignment = xlGeneral
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
With Selection
.HorizontalAlignment = xlGeneral
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Columns("C:C").Select
Selection.ColumnWidth = 17.71
With Selection
.HorizontalAlignment = xlGeneral
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Range("A1").Select
Selection.AutoFilter
MsgBox "All CofAs have now been imported"
Application.ScreenUpdating = True
End Sub
Thanks for looking