Have Questions? 
help@excelvbaisfun.com
Excel Ninja Pro
All Access

March 23, 2018

How To Prompt For A File In Excel VBA

If you need to Prompt to open a file in Excel VBA, check out the below code snippet. Please leave us a comment below if you have questions or comments and share this page if you think it can help others!

Sub grabOpenOtherWorkbook()
'declare other workbook so we can use Intellisense (autofill)
Dim othWb As Workbook

'prompt for the workbook to Open
myFile = Application.GetOpenFilename()
If myFile = Empty Then Exit Sub

'open that workbook
Set othWb = Workbooks.Open(myFile)

End Sub

You can now manipulate the other workbook, because we told Excel that the other workbook will be referred to from now on as othWb, so we can do things we normally would do with a Workbook object, such as:

'Update a Cell Value
othWb.range("a1") = "New Value"
'Or Close The Other Workbook
othWb.Close SaveChanges:=True

**New To VBA?: In these Excel VBA Posts, you'll need to Open The Visual Basic Editor (VBE), and Make a New Module and then Create A New Macro (Subroutine) in order to paste the code below and use it. Start here ==>Click here for VBA Basics.**

Excel VBA Is Fun

We believe Excel is one of the most versatile programs out there - and learning to program and automate it makes you very valuable!

You can prevent wasted time and errors, speed up tasks and become indispensable to your organization. 

See how our trainees have gotten raises, promotions and bonuses using their Excel Automation skills while building real problem-solving programs in Excel!
LEARN MORE
Copyright © 2024 ExcelVbaIsFun
X

Forgot Password?

Join Us

0
    0
    Your Cart
    Your cart is emptyReturn to Shop
    linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram