folks, I have a macro that , so far, opens another workbook, copies a certain tab into thisworkbook, and now I am trying to close the second workbook. when I run the macro, I get a "subscript out of range" on the Workbooks(MLPwkb).Close False line.
here is my code:
Also, I can't seem to suppress the Microsoft Security Notice to enable or disable macros for the file I am opening. How is this done?
here is my code:
Code:
Option Explicit
Sub reportpackage()
Dim MyPath As String
Dim MyFile As String
Dim LatestFile As String
Dim LatestDate As Date
Dim LMD As Date
Dim MLPwkb As String, SourceWb As Workbook
Set SourceWb = ThisWorkbook
MyPath = \\FPMB1FNP02\Groups$\Internal_Management_Reports\DailyMLP
If Right(MyPath, 1) <> "\" Then MyPath = MyPath & "\"
MyFile = Dir(MyPath & "*.xls", vbNormal)
If Len(MyFile) = 0 Then
MsgBox "No files were found...", vbExclamation
Exit Sub
End If
Do While Len(MyFile) > 0
LMD = FileDateTime(MyPath & MyFile)
If LMD > LatestDate Then
LatestFile = MyFile
LatestDate = LMD
End If
MyFile = Dir
Loop
MLPwkb = MyPath & LatestFile
With Workbooks.Open(MLPwkb)
Application.DisplayAlerts = False
' .Sheets("MLP").UsedRange.Copy
End With
With SourceWb
.Sheets("MLP").Range("A1").PasteSpecial (xlPasteValues)
.Sheets("Dashboard").Range("N2") = LatestDate
End With
Workbooks(MLPwkb).Close False
End Sub
Also, I can't seem to suppress the Microsoft Security Notice to enable or disable macros for the file I am opening. How is this done?