ranjith2523
Board Regular
- Joined
- Apr 29, 2014
- Messages
- 137
- Office Version
- 365
Hi Experts,
I wrote the below coding to open a file based on wildcard file name match, the file is password protected file and i would like to open it as Read-Only, getting Compile or Syntax error when i try to add "ReadOnly:=True".
This method works ("Workbooks.Open Filename:="C:\DE6_AFTERREP3\SP_Files\FY21_TS_Price_contractual.XLSX", ReadOnly:=True") as expected but my expectation is to open the file based on wild card file name match.
Can someone help me to incorporate "Readonly = True" in below coding. Thanks for all your help in advance.
Regards,
Ranjith
I wrote the below coding to open a file based on wildcard file name match, the file is password protected file and i would like to open it as Read-Only, getting Compile or Syntax error when i try to add "ReadOnly:=True".
This method works ("Workbooks.Open Filename:="C:\DE6_AFTERREP3\SP_Files\FY21_TS_Price_contractual.XLSX", ReadOnly:=True") as expected but my expectation is to open the file based on wild card file name match.
Can someone help me to incorporate "Readonly = True" in below coding. Thanks for all your help in advance.
VBA Code:
Dim myFile As String
Dim myPath As String
myPath = "C:\DE6_AFTERREP3\SP_Files\"
myFile = Dir(myPath & "*TS_Price_contractual.xlsx", vbNormal)
If Len(myFile) = 0 Then
MsgBox "Agreement file not found...", vbExclamation
Exit Sub
End If
targetfile = myPath & myFile
Set wb = Workbooks.Open(targetfile) ReadOnly:=True
Set ws = wb.Sheets("FY_TS_Price_contractual")
wb.Sheets("FY21_Log").Cells.Copy ThisWorkbook.Sheets("Agreement_SP").Range("A1")
wb.Close
Regards,
Ranjith