I'm having problems assigning parameters to my .open methon in VBA for Excel. Below code is what I have, all I need is to open specified workbook as read-only and not editable.
How do I set up the parameters to work, Please and Thank You!
Dim source As Workbook Dim projekt, BOM As String Dim count As Integer Dim LastBOM As Long LastBOM = Ark1.Range("I" & Rows.count).End(xlUp).Row For count = 16 To LastBOM BOM = Range("I" & count) 'List of Excel workbooks in active workbook projekt = "[Path to file on drive]\" & BOM & ".xlsx" Workbooks.Open (projekt) '<= This works and open above specified workbook ' but should be read only and not editable Workbooks.Open(projekt,ReadOnly:=True,Editable:=False) '<= None of these work Workbooks.Open(projekt,,True,,,,,,,False,,,,,) Workbooks.Open(projekt,True,False) Workbooks.Open("projekt",True,False) Workbooks.Open(Filename:="projekt",True,False) Workbooks.Open(Filename:=projekt,ReadOnly:=True,Editable:=False) Workbooks.Open(Filename:="projekt",ReadOnly:=True,Editable:=False) Next count
Dim projekt, BOM As Stringonly declaresBOM As Stringbutprojekt As Variantyou need to specify a type for every variable:Dim projekt As String, BOM As Stringprojectis declared asVariant, not asString. No a big deal here, but in other cases this can lead to errors.Variant.