nwille7400
New Member
- Joined
- Dec 16, 2019
- Messages
- 6
- Office Version
- 365
- Platform
- Windows
Hello,
I set up a macro in a workbook (let's call this prog workbook) to open every workbook (let's call these spec workbooks) in a folder (about 2600 of them), copy information from the spec workbooks into yet another workbook (which is a revised template, call it temp workbook). After that is done the prog workbook macro runs a macro in the temp workbook to refresh with the new data. After that the spec workbook is closed and deleted from the folder and the temp workbook is saved as the spec workbook filename in the original spec workbook folder. This all seemed to work well, however, when I open up the new spec workbook (temp workbook saved with spec info and spec file name) it runs very slow. Clicking between tabs in this work book and running any macros go very slow.
Could anyone help me figure out what could be causing this? If I do this operation manually it doesn't result in a slow functioning workbook. See code below. Let me know if you have any questions. Thanks!!!
I set up a macro in a workbook (let's call this prog workbook) to open every workbook (let's call these spec workbooks) in a folder (about 2600 of them), copy information from the spec workbooks into yet another workbook (which is a revised template, call it temp workbook). After that is done the prog workbook macro runs a macro in the temp workbook to refresh with the new data. After that the spec workbook is closed and deleted from the folder and the temp workbook is saved as the spec workbook filename in the original spec workbook folder. This all seemed to work well, however, when I open up the new spec workbook (temp workbook saved with spec info and spec file name) it runs very slow. Clicking between tabs in this work book and running any macros go very slow.
Could anyone help me figure out what could be causing this? If I do this operation manually it doesn't result in a slow functioning workbook. See code below. Let me know if you have any questions. Thanks!!!
VBA Code:
Sub Button1_Click()
'this sets your template workbook/worksheet
Dim shp As Shape
'start code to update insp report
Dim copyWB As Workbook
Set copyWB = ThisWorkbook
'open insp report to copy from
file_name = "new inspection report_Rev E beta 7 safe.xls"
Set myTextFile = Workbooks.Open("X:\Inspection Reports\test\Beta version\" & file_name)
'this creates a collection of all filenames to be processed
Dim loopFolder As String
Dim fileNm As Variant
Dim myFiles As New Collection
'don't forget the backslash before the final double-quote below
loopFolder = ThisWorkbook.Sheets("Sheet1").Cells(3, 4) 'this is where the folder location is stated
fileNm = Dir(loopFolder & "*.xls")
Do While fileNm <> ""
myFiles.Add fileNm
fileNm = Dir
Loop
Application.DisplayAlerts = False
'this loops through all filenames
Dim wb As Workbook
insp_report_name = ""
For Each fileNm In myFiles
Set wb = Workbooks.Open(Filename:=(loopFolder & fileNm)) 'open each workbook in the folder
'check to see if the 'Update Reports' button was removed. If it was then we should update manually
On Error Resume Next 'incase shape does not exist
Set shp = wb.Sheets("Input Sheet").Shapes("Button 314")
If shp Is Nothing Then
MsgBox "Shape does not exist."
wb.Close
Else
wb.Sheets("Input Sheet").Range("A5:I13").Copy _
myTextFile.Sheets("Input Sheet").Range("A5") 'copy input sheet data to new sheet
wb.Sheets("Input Sheet").Range("A15:E23").Copy _
myTextFile.Sheets("Input Sheet").Range("A16")
wb.Sheets("Input Sheet").Range("F15:I23").Copy _
myTextFile.Sheets("Input Sheet").Range("F15")
wb.Sheets("Input Sheet").Range("E30:E37").Copy _
myTextFile.Sheets("Input Sheet").Range("E31")
wb.Sheets("Insp. Sheet Final").Range("B1:B3").Copy _
myTextFile.Sheets("Insp. Sheet Final").Range("B1") 'copy final sheet info
'wb.Sheets("Insp. Sheet Final").Range("B5:B7").Copy _
'myTextFile.Sheets("Insp. Sheet Final").Range("B4") 'don't need job number or order/ship qtys
If wb.Sheets("Input Sheet").Checkbox8 = True Then 'check to sheet if checkboxes in input sheet are checked and make new insp sheet the same
If wb.Sheets("Input Sheet").CheckBox11 = True Then
myTextFile.Sheets("Input Sheet").CheckBox10 = False
myTextFile.Sheets("Input Sheet").Cells(41, 3) = 2
myTextFile.Sheets("Input Sheet").Cells(28, 2) = 0.0003
End If
Else
myTextFile.Sheets("Input Sheet").CheckBox9 = True 'code from checkboxes
myTextFile.Sheets("Input Sheet").Rows("25:38").EntireRow.Hidden = True
myTextFile.Sheets("Input Sheet").Shapes("Check Box 1214").OLEFormat.Object.Visible = False
myTextFile.Sheets("Input Sheet").Shapes("Check Box 1215").OLEFormat.Object.Visible = False
myTextFile.Sheets("Input Sheet").Shapes("Check Box 1216").OLEFormat.Object.Visible = False
myTextFile.Sheets("Input Sheet").Shapes("Check Box 1217").OLEFormat.Object.Visible = False
myTextFile.Sheets("Input Sheet").Shapes("Check Box 1218").OLEFormat.Object.Visible = False
myTextFile.Sheets("Input Sheet").Shapes("Check Box 1219").OLEFormat.Object.Visible = False
myTextFile.Sheets("Input Sheet").Shapes("Check Box 1220").OLEFormat.Object.Visible = False
myTextFile.Sheets("Input Sheet").Shapes("Check Box 1221").OLEFormat.Object.Visible = False
myTextFile.Sheets("Input Sheet").OLEObjects("Checkbox10").Visible = False
myTextFile.Sheets("Input Sheet").OLEObjects("Checkbox11").Visible = False
myTextFile.Sheets("Input Sheet").Cells(42, 3) = 2
End If
insp_report_name = wb.Name 'record name of specific insp report
wb.Close 'close specific insp report
Kill loopFolder & insp_report_name 'delete specific insp report
myTextFile.SaveAs Filename:=loopFolder & insp_report_name 'save new inspection report as specific insp report name
Application.Run ("'" & myTextFile.Name & "'!Update")
Sheets("Insp. Sheet Final").Activate
myTextFile.Save
End If
Next
Application.DisplayAlerts = True
End Sub