I have a formula in P2 that creates a string formula the following macro then places it in to A5, if what is up to (2) is ran it works fine, up to (3) pastes before SendKeys runs so formula isn't active and, if I run to end with or with without (2) then protect is activated before formula.
Is there a better way to place and activate this formula in the whole range so sheet still protects?
Application.ScreenUpdating = False
Application.DisplayStatusBar = False
Dim wsheet As Worksheet
For Each wsheet In ActiveWorkbook.Worksheets
wsheet.UNPROTECT Password:="TRADE"
Next wsheet
'(1)****************************************************************************************
Range("P2").Copy
Range("A5").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
SendKeys "{F2}"
SendKeys "{ENTER}"
'(2)*****************************************************************************************
Range("A5").Copy Range("A6:A12")
'(3)*****************************************************************************************
filetoopen = ThisWorkbook.Worksheets("CSV COLLECT").Range("V3")
Workbooks.Open fileName:=filetoopen
ActiveWorkbook.Close ("A5")
For Each wsheet In ActiveWorkbook.Worksheets
wsheet.PROTECT Password:="TRADE"
Next wsheet
Application.ScreenUpdating = True
Application.DisplayStatusBar = True
End Sub
Is there a better way to place and activate this formula in the whole range so sheet still protects?
Application.ScreenUpdating = False
Application.DisplayStatusBar = False
Dim wsheet As Worksheet
For Each wsheet In ActiveWorkbook.Worksheets
wsheet.UNPROTECT Password:="TRADE"
Next wsheet
'(1)****************************************************************************************
Range("P2").Copy
Range("A5").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
SendKeys "{F2}"
SendKeys "{ENTER}"
'(2)*****************************************************************************************
Range("A5").Copy Range("A6:A12")
'(3)*****************************************************************************************
filetoopen = ThisWorkbook.Worksheets("CSV COLLECT").Range("V3")
Workbooks.Open fileName:=filetoopen
ActiveWorkbook.Close ("A5")
For Each wsheet In ActiveWorkbook.Worksheets
wsheet.PROTECT Password:="TRADE"
Next wsheet
Application.ScreenUpdating = True
Application.DisplayStatusBar = True
End Sub