Get data from a separate workbook in a different location WITHOUT opening it

Woftae

New Member
Joined
Feb 10, 2018
Messages
24
I have an excel file that needs to reference another excel workbook that is in another location (directory) so file path needs to be included.
I do not want to have to open this external workbook as it is in constant use by another user and it is a large file and slow to open and close etc.
But the code I've written keeps returning a runtime error: 9 Subscript out of range. indicate with code in green below.
I have tried many different code configurations but have not been able to get it to work yet.
My current/latest code is attached.
Thank in advance for any assistance.

'Sub GetOrderInfo(lastrow)
Sub GetOrderInfo()

Dim WBOrders As String
WBOrders = "Z:\Suppliers Orders\Suppliers Orders V4.3.xlsm"

Dim WshOrders As String
WshOrders = "Orders"

Dim WshPrevious As Worksheet
Dim WshLatest As Worksheet

Set WshLatest = Sheets("Latest")
Set WshPrevious = Sheets("Previous")

Dim LLastRow As Integer
LLastRow = Sheets("Latest").Range("A" & Rows.Count).End(xlUp).Row + 1

Dim PLastRow As Integer
PLastRow = Sheets("Previous").Range("A" & Rows.Count).End(xlUp).Row + 1

Dim OLastRow As Integer

MsgBox Dir("Z:\Suppliers Orders\Suppliers Orders V4.3.xlsm")
OLastRow = Workbooks(WBOrders).Worksheets(WshOrders).Range("A" & Rows.Count).End(xlUp).Row + 1 '<<< Error occurs here

Dim OStartRow As Integer
OStartRow = OLastRow - 1000

Dim OrderFound As String
OrderFound = ""

Dim OSupName As String
OSupName = ""

Dim Li As Integer
Li = LLastRow
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Have a look at this
 
Upvote 0
Hi Zot, thankyou for your response and I am very sorry for my slow response, I will defiantly check your reference and let you know how I went.
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,160
Members
453,021
Latest member
Justyna P

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