View Single Post
 
Old 01-17-2014, 02:53 PM
BobBridges's Avatar
BobBridges BobBridges is offline Windows 7 64bit Office 2010 32bit
Expert
 
Join Date: May 2013
Location: USA
Posts: 700
BobBridges has a spectacular aura aboutBobBridges has a spectacular aura about
Default

Ah. Yeah, recording the macro won't help you learn to use the file-open dialogue.

But if I just write a snippet of code for you, that probably won't help you either, because you won't understand how to plug it into the program you already have. I mean, that link I gave you had code examples; presumably you glanced at them and knew they wouldn't help because you don't know enough to adapt them to your program. I don't see how I can do any better, from that angle.

The best I can do is teach you how to write it. I'm willing, but are you? If not, maybe you have a coworker who can?

Let me remind myself how it works and then give you a sample or two. ....Well, maybe it's simpler than I remembered. The most basic way to use it is simply to say
Code:
filename=Application.GetOpenFilename
Plug that into your program and run it to see what happens. If the user selected a file and hit the Open button, the file path and name come back and end up in the variable. If the user hit the Cancel button, you get back the False value. There's a warning in the documentation that the dialogue may change the "current directory"; that's because this version of the dialogue starts in the current directory and the user has to navigate if the file he wants is in a different folder.

So that's the first complication: If the current directory isn't when the desired files are, your program should probably set the current directory before calling the dialogue.

There are other wrinkles you can incorporate. You can set it so it displays just .xlsx files, for example. There's also a setting that lets the user select more than one file, though I gather that isn't what you need in this case. And if you need the user to point to a folder instead of a file, it requires a different dialogue. But that's the general idea.

If you want to understand more than that, I'm willing to explain. But it kind of requires you to learn more VBA. Some people like that idea, some don't. Up to you; I used to sneer at people who don't want to learn, but eventually I decided that if everyone wanted to learn there'd be no one left to do the actual work, so I'm content now.
Reply With Quote