I have the following macro which increases/decreases material pricing from one "Master Key" to multiple files (pricing templates) in an "/Update/" folder. This macro worked fine for Excel 2011 but when we moved to Excel 2016 it is asking permission to open a folder and I can't select the folder to give it permission.
I reviewed THIS ARTICLE which explains how to fix the situation but honestly I'm confused how I can incorporate that code into my code.
Any guidance would be much appreciated!
See code below:
I reviewed THIS ARTICLE which explains how to fix the situation but honestly I'm confused how I can incorporate that code into my code.
Any guidance would be much appreciated!
See code below:
Code:
Sub FactorChange_Price() Dim MyPath As String, FilesInPath As String
Dim MyFiles() As String, Fnum As Long
Dim Filename As String
Dim mybook As Workbook
Dim CalcMode As Long
Dim sh As Worksheet
Dim ErrorYes As Boolean
'Fill in the path\folder where the files are
MyPath = Application.ActiveWorkbook.Path & "/Update/"
'If there are no Excel files in the folder exit the sub
FilesInPath = Dir(MyPath)
If FilesInPath = "" Then
MsgBox "No files found"
Exit Sub
End If
'Fill the array(myFiles)with the list of Excel files in the folder
Fnum = 0
Do While FilesInPath <> ""
Fnum = Fnum + 1
ReDim Preserve MyFiles(1 To Fnum)
MyFiles(Fnum) = FilesInPath
FilesInPath = Dir()
Loop
With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
.EnableEvents = False
End With
'Loop through all files in the array(myFiles)
If Fnum > 0 Then
For Fnum = LBound(MyFiles) To UBound(MyFiles)
Set mybook = Nothing
On Error Resume Next
Set mybook = Workbooks.Open(MyPath & MyFiles(Fnum))
If Not mybook Is Nothing Then
'Change cell value(s) in one worksheet in mybook
With mybook.Worksheets("Project")
.Range("A1").Value = "Success"
'.Range("O63:O73").Value = .Range("O63:O73").Value + Workbooks("Master_Key").Worksheets("Master_Key").Range("D4:D14").Value
.Range("G25") = Format(Now(), "mm-dd-yy")
.Range("H25") = Format(Workbooks("Master_Key.xlsm").Worksheets("Master_Key").Range("C27").Value, "mm-dd-yy")
.Range("I25") = Format(Workbooks("Master_Key.xlsm").Worksheets("Master_Key").Range("D27").Value, "mm-dd-yy")
'.Range("G19") = DateAdd("m", 3, Now())
'.Range("O63:O73").Value = Workbooks("Master_Key.xlsm").Worksheets("Master_Key").Range("C4:C14").Value
'Material Cost Factor Change Formulas
.Range("E17") = .Range("E17") + Workbooks("Master_Key.xlsm").Worksheets("Master_Key").Range("D4").Value
.Range("E18") = .Range("E18") + Workbooks("Master_Key.xlsm").Worksheets("Master_Key").Range("D5").Value
.Range("E19") = .Range("E19") + Workbooks("Master_Key.xlsm").Worksheets("Master_Key").Range("D6").Value
.Range("E20") = .Range("E20") + Workbooks("Master_Key.xlsm").Worksheets("Master_Key").Range("D7").Value
.Range("E21") = .Range("E21") + Workbooks("Master_Key.xlsm").Worksheets("Master_Key").Range("D8").Value
.Range("E22") = .Range("E22") + Workbooks("Master_Key.xlsm").Worksheets("Master_Key").Range("D9").Value
.Range("E23") = .Range("E23") + Workbooks("Master_Key.xlsm").Worksheets("Master_Key").Range("D10").Value
.Range("E24") = .Range("E24") + Workbooks("Master_Key.xlsm").Worksheets("Master_Key").Range("D11").Value
.Range("E25") = .Range("E25") + Workbooks("Master_Key.xlsm").Worksheets("Master_Key").Range("D12").Value
.Range("E26") = .Range("E26") + Workbooks("Master_Key.xlsm").Worksheets("Master_Key").Range("D13").Value
.Range("E27") = .Range("E27") + Workbooks("Master_Key.xlsm").Worksheets("Master_Key").Range("D14").Value
End With
Application.Calculate
Filename = Range("C11")
ActiveWorkbook.ChangeFileAccess Mode:=xlReadWrite
Application.ActiveWorkbook.SaveAs Application.ActiveWorkbook.Path & ":" & Filename, FileFormat:=53
mybook.Close savechanges:=False
End If
Next Fnum
End If
With Application
.ScreenUpdating = True
.EnableEvents = True
.Calculation = CalcMode
End With
End Sub