jordanburch
Active Member
- Joined
- Jun 10, 2016
- Messages
- 443
- Office Version
- 2016
Hi all,
I have the below. It is giving me the pop up of that is already enabled in vba. Basically I want it to enable ad ins if they are disabled. I added the part where it enables them and it seems to work but it gives methat pop up and doesnt continue in the loop. I just want it to enable add ins to run code on the file. Any help is appreciated!
Jordan
Sub LoopThroughFiles()
Dim MyObj As Object
Dim MySource As Object
Dim file As Variant
Dim wbThis As Workbook 'workbook where the data is to be pasted, aka Master file
Dim wbTarget As Workbook 'workbook from where the data is to be copied from, aka Overnights file
Dim LastRow As Long
Dim sht1 As Worksheet
Dim sht2 As Worksheet
Application.DisplayAlerts = False
'set to the current active workbook (the source book, the Master!)
Set wbThis = ActiveWorkbook
Set sht1 = wbThis.Sheets("Cleared")
Folder = "C:\Users\jordan.burch.ctr\Desktop\Cert Statements\"
Fname = Dir(Folder)
While (Fname <> "")
Set wbTarget = Workbooks.Open(FileName:=Folder & Fname)
wbTarget.Activate
Application.DisplayAlerts = False
If AddIns("Analysis ToolPak").Installed = True Then _
MsgBox "Analysis ToolPak is already installed" & vbCrLf & _
"", 48, "Be Advised..."
On Error GoTo ErrorHandler
If Not AddIns("Analysis ToolPak").Installed Then
AddIns("Analysis ToolPak").Installed = True
AddIns("Analysis ToolPak - VBA").Installed = True
End If
Exit Sub
ErrorHandler:
MsgBox "FYI, the Analysis ToolPak is not available on your system," & vbCrLf & _
"some operations in this workbook may function properly.", 48, "Be advised..."
Err.Clear
Dim ws As Worksheet
Dim ClearedSheet As String
ClearedSheet = ""
For Each ws In ActiveWorkbook.Worksheets
If InStr(1, ws.Name, "Clear", vbTextCompare) Then
ClearedSheet = ws.Name
Sheets(ClearedSheet).Activate
With ActiveSheet
If .AutoFilterMode Then
If .FilterMode Then
.ShowAllData
End If
Else
If .FilterMode Then
.ShowAllData
End If
End If
End With
Exit For
End If
Application.DisplayAlerts = False
Next
If ClearedSheet <> "" Then
' Sheets("Cleared - Cleared to").Activate
' With ActiveSheet
' If .AutoFilterMode Then
' If .FilterMode Then
' .ShowAllData
' End If
' Else
' If .FilterMode Then
' .ShowAllData
' End If
' End If
' End With
Range("a2:aw40000").Copy
wbThis.Activate
'Just add this line:
LastRow = sht1.Range("b1").End(xlDown).Row + 1
'And alter this one as follows:
sht1.Range("a" & Range("A" & Rows.Count).End(xlUp).Row + 1).PasteSpecial
Fname = Dir
'close the overnight's file
wbTarget.Close
End If
Wend
Application.DisplayAlerts = True
End Sub
I have the below. It is giving me the pop up of that is already enabled in vba. Basically I want it to enable ad ins if they are disabled. I added the part where it enables them and it seems to work but it gives methat pop up and doesnt continue in the loop. I just want it to enable add ins to run code on the file. Any help is appreciated!
Jordan
Sub LoopThroughFiles()
Dim MyObj As Object
Dim MySource As Object
Dim file As Variant
Dim wbThis As Workbook 'workbook where the data is to be pasted, aka Master file
Dim wbTarget As Workbook 'workbook from where the data is to be copied from, aka Overnights file
Dim LastRow As Long
Dim sht1 As Worksheet
Dim sht2 As Worksheet
Application.DisplayAlerts = False
'set to the current active workbook (the source book, the Master!)
Set wbThis = ActiveWorkbook
Set sht1 = wbThis.Sheets("Cleared")
Folder = "C:\Users\jordan.burch.ctr\Desktop\Cert Statements\"
Fname = Dir(Folder)
While (Fname <> "")
Set wbTarget = Workbooks.Open(FileName:=Folder & Fname)
wbTarget.Activate
Application.DisplayAlerts = False
If AddIns("Analysis ToolPak").Installed = True Then _
MsgBox "Analysis ToolPak is already installed" & vbCrLf & _
"", 48, "Be Advised..."
On Error GoTo ErrorHandler
If Not AddIns("Analysis ToolPak").Installed Then
AddIns("Analysis ToolPak").Installed = True
AddIns("Analysis ToolPak - VBA").Installed = True
End If
Exit Sub
ErrorHandler:
MsgBox "FYI, the Analysis ToolPak is not available on your system," & vbCrLf & _
"some operations in this workbook may function properly.", 48, "Be advised..."
Err.Clear
Dim ws As Worksheet
Dim ClearedSheet As String
ClearedSheet = ""
For Each ws In ActiveWorkbook.Worksheets
If InStr(1, ws.Name, "Clear", vbTextCompare) Then
ClearedSheet = ws.Name
Sheets(ClearedSheet).Activate
With ActiveSheet
If .AutoFilterMode Then
If .FilterMode Then
.ShowAllData
End If
Else
If .FilterMode Then
.ShowAllData
End If
End If
End With
Exit For
End If
Application.DisplayAlerts = False
Next
If ClearedSheet <> "" Then
' Sheets("Cleared - Cleared to").Activate
' With ActiveSheet
' If .AutoFilterMode Then
' If .FilterMode Then
' .ShowAllData
' End If
' Else
' If .FilterMode Then
' .ShowAllData
' End If
' End If
' End With
Range("a2:aw40000").Copy
wbThis.Activate
'Just add this line:
LastRow = sht1.Range("b1").End(xlDown).Row + 1
'And alter this one as follows:
sht1.Range("a" & Range("A" & Rows.Count).End(xlUp).Row + 1).PasteSpecial
Fname = Dir
'close the overnight's file
wbTarget.Close
End If
Wend
Application.DisplayAlerts = True
End Sub