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>
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
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
 
Upvote 0
Did you try the code I supplied, or just modified yours?
 
Upvote 0

Forum statistics

Threads
1,214,987
Messages
6,122,613
Members
449,090
Latest member
vivek chauhan

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top