The syntax of Workbooks.Open
is
expression.Open(FileName, UpdateLinks, ReadOnly, Format, Password, WriteResPassword, IgnoreReadOnlyRecommended, Origin, Delimiter, Editable, Notify, Converter, AddToMru, Local, CorruptLoad)
Is this what you are trying?
Sub Sample()
openBook "C:\MyFile.xlsx", False, True
End Sub
Sub openBook(fileName As String, UpdtLink As Boolean, RdOnly As Boolean)
Application.Workbooks.Open fileName, UpdtLink, RdOnly
End Sub
EDIT
If you want to pass 0/False
and 1/True
then you will have to change
Sub openBook(fileName As String, UpdtLink As Boolean, RdOnly As Boolean)
to
Sub openBook(fileName As String, UpdtLink As Variant, RdOnly As Variant)
FOLLOWUP FROM COMMENTS
is there anyway to also activate that workbook in the same line or would another line of code be required? – metsales 1 min ago
Why do you want to activate it? .Activate
should be avoided as much as possible. You might want to see THIS
Having said that, if you want to activate it then you have to use a code like this
Sub Sample()
openBook "C:\MyFile.xlsx", False, True
End Sub
Sub openBook(fileName As String, UpdtLink As Boolean, RdOnly As Boolean)
Dim wb As Workbook
Set wb = Application.Workbooks.Open(fileName, UpdtLink, RdOnly)
wb.Activate
End Sub
However the below is what I would suggest based on my earlier advice about not to use .Activate
Dim wb As Workbook
Sub Sample()
openBook "C:\MyFile.xlsx", False, True
DoEvents
With wb
'
'~~> Do something with the workbook here
'
End With
End Sub
Sub openBook(fileName As String, UpdtLink As Boolean, RdOnly As Boolean)
Set wb = Application.Workbooks.Open(fileName, UpdtLink, RdOnly)
End Sub