The code below, located in my access database, runs fine half of the time. The other half it gives me: "error 9 subscript out of range," and it highlights the "Set WKS = Workbooks(..." line as the problem. I know that the problem is with it being unsure which workbook it is referencing. However I don't know what to do to make it clearer.
Sub fixborderss() Dim WKS As Excel.Worksheet Dim lastrow As Long Set WKS = Workbooks("L3 PSR.xls").Worksheets("L-3 Project Status Report") lastrow = Range("I" & WKS.Rows.Count).End(xlUp).Row WKS.Range("A8:V" & lastrow).Borders(xlEdgeTop).Color = RGB(191, 191, 191) WKS.Range("A8:V" & lastrow).Borders(xlEdgeBottom).Color = RGB(191, 191, 191) WKS.Range("A8:V" & lastrow).Borders.LineStyle = xlContinuous End Sub
L3 PSR.xlsopen when this is run?Excel.Applicationinstance which has the workbook opened. QualifyWorkbookswith that object variable ...Set WKS = objExcel.Workbooks(lastrow = Range(, change that tolastrow = WKS.Range(Set XL = GetObject("C:\Users\****\Desktop\L3 PSR.xls").Applicationto find the instance in question, and threw that in the front of the WKS variable assignment. Thanks again.