vba

Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

Forum home » Delegate support and help forum » Microsoft Excel Training and help » VBA

VBA

resolvedResolved · Low Priority · Version 2016

Jiyu has attended:
Excel VBA Intermediate course
Excel VBA Introduction course

VBA

Can I use VBA to retrieve data from other workbooks without needing to open those workbooks?

RE: VBA


Hi Jiyu,

Thank you for the question and I hope you are fine.

Below you can find an example. In my example the code will open a workbook, get the data, and close the workbook we have retrieved the data from. I hope the example makes sense.


Sub Example1()
Dim objWorkbook As Workbook
Dim i As Integer
'open the workbook with data
Set objWorkbook = Workbooks.Open( _
"D:StuffBusinessTempData.xlsx")
'read the data from the first columns
For i = 1 To 9
Cells(i, 1) = _
objWorkbook.Worksheets("Sheet1").Cells(i + 1, 1)
Next i
'close the workbook
objWorkbook.Close
End Sub


Kind regards

Jens Bonde
Microsoft Office Specialist Trainer

Tel: 0207 987 3777
STL - https://www.stl-training.co.uk
98%+ recommend us

London's leader with UK wide delivery in Microsoft Office training and management training to global brands, FTSE 100, SME's and the public sector


 

Excel tip:

Stop Formula Returning A "#DIV/0" Error

If a formula returns a #DIV/0 error message there is a way to avoid such results.

For example the formula =A1/B1 will return a #DIV/0 if B1 is empty or a zero.

If you protect your formulas with the ISERROR function, the formula will then look like this:

=IF(ISERROR(A1/B1),0,A1/B1)

In plain English: should the result of A1 divided by B1 be an error change the result to 0 else show the result of A1/B1.

View all Excel hints and tips


Server loaded in 0.13 secs.