run time error 9 in a Set statement

micos excel

New Member
Joined
Dec 25, 2017
Messages
2
When this sub is run a get run time error (subscript out of range) at stared statement.
I know the location is correct because I used this location to open the workbook.

This error message does not seem to apply this statement.

Help


Sub SingleRecord()<o:p></o:p>

Rem Records payroll data inrecords file<o:p></o:p>
Static bFileopen As Boolean<o:p></o:p>
Dim wbRec As Workbook<o:p></o:p>
Dim wbPR As Workbook<o:p></o:p>
Workbooks.Open"I:\Rosy's\Pay Roll\2017 Pay Records .xlsm"<o:p></o:p>
Set wbPR =Workbooks("FinalPAYROLL.xlsm")<o:p></o:p>
***** Set wbRec =Workbooks("I:\Rosy's\Pay Roll\2017 Pay Records.xlsm")<o:p></o:p>
' wbRec.Unprotect<o:p></o:p>
 

Some videos you may like

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
46,335
Office Version
  1. 365
Platform
  1. Windows
Hi & welcome to MrExcel
How about
Code:
Sub SingleRecord()
Rem Records payroll data inrecords file
Static bFileopen As Boolean
Dim wbRec As Workbook
Dim wbPR As Workbook
Set wbRec = Workbooks.Open("I:\Rosy's\Pay Roll\2017 Pay Records .xlsm")
Set wbPR = Workbooks("FinalPAYROLL.xlsm")
' wbRec.Unprotect
PS in your code you have a space between records & .xlsm when you open it, but not when you try to set wbRec
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
46,335
Office Version
  1. 365
Platform
  1. Windows
Did you try the code I supplied, or just modified yours?
 

Watch MrExcel Video

Forum statistics

Threads
1,109,004
Messages
5,526,225
Members
409,689
Latest member
martin_br

This Week's Hot Topics

Top