marionffavp
New Member
- Joined
- Nov 11, 2016
- Messages
- 3
Hi Everyone,
What I am trying to accomplish is to have an Excel 2013 file that will open and automatically do the following:
1.) Open a different Excel workbook ("Workbook2") from a SharePoint Site as read only.
2.) Apply a filter on two different columns for the ("Workbook2") Excel workbook.
3.) Copy the values from 6 different columns into the next usable row of the originating workbook ("Workbook1").
4.) Remove any duplicates that are found in the first workbook("Workbook1").
5.) close the ("Workbook2") file.
The problem I am having is that ("Workbook2") is not getting the filter applied to it, but ("Workbook1") is and that is not what needs to happen. The really funny thing is that it worked perfectly when I stepped through the code using F8. That's what I get for not REALLY testing it out with a final run.
below is the code:
Private Sub Workbook_Open()
'
'
Dim CurWorkbook As Workbook
Dim Workbook1EndRow As Long
Dim Workbook1StartCopyRow As Long
Dim Workbook2EndRow As Long
Dim Workbook1AfterPasteRow As Long
Application.DisplayAlerts = False
Application.ScreenUpdating = False
Application.DisplayStatusBar = False
Application.EnableEvents = False
Set CurWorkbook = ActiveWorkbook
Workbooks.Open "SharePoint Site Link", ReadOnly:=True
Workbooks("Workbook2").Sheets("Sheet1").Activate 'This is where the error occurs.
With ActiveSheet
.AutoFilterMode = False
.UsedRange.AutoFilter
.UsedRange.AutoFilter field:=37, Criteria1:=xlFilterYesterday, Operator:=xlFilterDynamic
.UsedRange.AutoFilter field:=29, Criteria1:="*criteria*"
End With
Workbooks("Workbook1").Sheets("Sheet1").Activate
Workbook1EndRow = Cells(Rows.Count, 1).End(xlUp).Row
Workbook1StartCopyRow = Cells(Rows.Count, 1).End(xlUp).Row + 1
'Copy and paste the values starting from the starting cell number.
'Get the notification number
Range("AD2").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Workbooks("Workbook1").Activate
ActiveSheet.Paste Destination:=Cells(Workbook1StartCopyRow, 1)
Application.CutCopyMode = False
'Get the Created on Date
Windows("Workbook2").Activate
Range("AK2").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Workbooks("Workbook1").Activate
ActiveSheet.Paste Destination:=Cells(Workbook1StartCopyRow, 2)
Application.CutCopyMode = False
'Get the Serial Number
Windows("Workbook2").Activate
Range("AB2").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Workbooks("Workbook1").Activate
ActiveSheet.Paste Destination:=Cells(Workbook1StartCopyRow, 3)
Application.CutCopyMode = False
'Get the Description
Windows("Workbook2").Activate
Range("AC2").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Workbooks("Workbook1").Activate
ActiveSheet.Paste Destination:=Cells(Workbook1StartCopyRow, 4)
Application.CutCopyMode = False
'Get the Long Text.
Windows("Workbook2").Activate
Range("K2").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Workbooks("Workbook1").Activate
ActiveSheet.Paste Destination:=Cells(Workbook1StartCopyRow, 5)
Application.CutCopyMode = False
'Get the Activity Text
Windows("Workbook1").Activate
Range("L2").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Workbooks("Workbook1").Activate
ActiveSheet.Paste Destination:=Cells(Workbook1StartCopyRow, 6)
Application.CutCopyMode = False
'Find the duplicate range to remove duplicates from.
Workbook1AfterPasteRow = Cells(Rows.Count, 1).End(xlUp).Row
'remove duplicates.
ActiveSheet.Range("$A:I").RemoveDuplicates Columns:=1, Header:=xlYes
Workbooks("workbook2").Close
Application.DisplayAlerts = True
Application.ScreenUpdating = True
Application.DisplayStatusBar = True
Application.EnableEvents = True
End Sub
What I am trying to accomplish is to have an Excel 2013 file that will open and automatically do the following:
1.) Open a different Excel workbook ("Workbook2") from a SharePoint Site as read only.
2.) Apply a filter on two different columns for the ("Workbook2") Excel workbook.
3.) Copy the values from 6 different columns into the next usable row of the originating workbook ("Workbook1").
4.) Remove any duplicates that are found in the first workbook("Workbook1").
5.) close the ("Workbook2") file.
below is the code:
Private Sub Workbook_Open()
'
'
Dim CurWorkbook As Workbook
Dim Workbook1EndRow As Long
Dim Workbook1StartCopyRow As Long
Dim Workbook2EndRow As Long
Dim Workbook1AfterPasteRow As Long
Application.DisplayAlerts = False
Application.ScreenUpdating = False
Application.DisplayStatusBar = False
Application.EnableEvents = False
Set CurWorkbook = ActiveWorkbook
Workbooks.Open "SharePoint Site Link", ReadOnly:=True
Workbooks("Workbook2").Sheets("Sheet1").Activate 'This is where the error occurs.
With ActiveSheet
.AutoFilterMode = False
.UsedRange.AutoFilter
.UsedRange.AutoFilter field:=37, Criteria1:=xlFilterYesterday, Operator:=xlFilterDynamic
.UsedRange.AutoFilter field:=29, Criteria1:="*criteria*"
End With
Workbooks("Workbook1").Sheets("Sheet1").Activate
Workbook1EndRow = Cells(Rows.Count, 1).End(xlUp).Row
Workbook1StartCopyRow = Cells(Rows.Count, 1).End(xlUp).Row + 1
'Copy and paste the values starting from the starting cell number.
'Get the notification number
Range("AD2").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Workbooks("Workbook1").Activate
ActiveSheet.Paste Destination:=Cells(Workbook1StartCopyRow, 1)
Application.CutCopyMode = False
'Get the Created on Date
Windows("Workbook2").Activate
Range("AK2").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Workbooks("Workbook1").Activate
ActiveSheet.Paste Destination:=Cells(Workbook1StartCopyRow, 2)
Application.CutCopyMode = False
'Get the Serial Number
Windows("Workbook2").Activate
Range("AB2").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Workbooks("Workbook1").Activate
ActiveSheet.Paste Destination:=Cells(Workbook1StartCopyRow, 3)
Application.CutCopyMode = False
'Get the Description
Windows("Workbook2").Activate
Range("AC2").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Workbooks("Workbook1").Activate
ActiveSheet.Paste Destination:=Cells(Workbook1StartCopyRow, 4)
Application.CutCopyMode = False
'Get the Long Text.
Windows("Workbook2").Activate
Range("K2").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Workbooks("Workbook1").Activate
ActiveSheet.Paste Destination:=Cells(Workbook1StartCopyRow, 5)
Application.CutCopyMode = False
'Get the Activity Text
Windows("Workbook1").Activate
Range("L2").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Workbooks("Workbook1").Activate
ActiveSheet.Paste Destination:=Cells(Workbook1StartCopyRow, 6)
Application.CutCopyMode = False
'Find the duplicate range to remove duplicates from.
Workbook1AfterPasteRow = Cells(Rows.Count, 1).End(xlUp).Row
'remove duplicates.
ActiveSheet.Range("$A:I").RemoveDuplicates Columns:=1, Header:=xlYes
Workbooks("workbook2").Close
Application.DisplayAlerts = True
Application.ScreenUpdating = True
Application.DisplayStatusBar = True
Application.EnableEvents = True
End Sub