I searched the forum and couldn't find an answer that would fit my problem. I am pretty new to Excel VBA and am having trouble activating a workbook I just opened. Directly below is the part that is causing me trouble.
So I press a button and it brings me to the file path, and I select a file to open. Every week this file has a different name and I am not really sure what it is until I open the file path and look at it.
Once I open it, I would like my macro to manipulate the data in the file and copy and paste into the workbook running the code. However when I run this macro and open the file it will not activate the newly opened workbook and runs the rest of the macro trying to manipulate the data in the original file.
I think I either need to open the file differently so that the workbook I just opened is the active one or figure out how to activate the newly opened workbook without knowing the file name. Thank you for your help.
Dim filepath As String
filepath = Environ("USERPROFILE") & "\Dropbox\On the go ordering"
Call Shell("explorer.exe" & " " & filepath, vbNormalFocus)
Range("A6:E500").Select
Sub on_the_go_button()
Dim RANKER As Workbook
Set RANKER = ThisWorkbook
Dim filepath As String
filepath = Environ("USERPROFILE") & "\Dropbox\On the go ordering"
Call Shell("explorer.exe" & " " & filepath, vbNormalFocus)
Range("A6:E500").Select
Selection.Copy
Sheets.Add After:=Sheets(Sheets.Count)
ActiveSheet.Paste
Application.CutCopyMode = False
Selection.AutoFilter
ActiveSheet.Range("$A$1:$E$495").AutoFilter Field:=1, Criteria1:=RGB(213, _
223, 248), Operator:=xlFilterCellColor
Range("G1").Select
ActiveCell.FormulaR1C1 = _
"=IF(RIGHT(RC[-6],8)=""Subtotal"",VALUE(LEFT(RC[-6],6)),"""")"
Range("H1").Select
ActiveCell.FormulaR1C1 = "=IF(RC[-1]="""","""",RC[-4])"
Range("I1").Select
ActiveCell.FormulaR1C1 = "=IF(RC[-1]="""","""",RC[-4])"
Range("G1:I1").Select
Selection.Copy
Range("G1:I500").Select
Selection.PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Selection.Copy
RANKER.Activate
Range("A1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("P1:Q74").Select
Selection.Copy
Sheets("Contest").Select
Range("A3").Select
ActiveCell.End(xlToRight).Select
ActiveCell.Offset(0, 1).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
End Sub