- How to open a folder in Windows Explorer from VBA?
- 11 Answers 11
- Explanation:
- Open folder in VS Code from Windows Explorer
- 2 Answers 2
- Windows 10 file explorer not opening? Can’t open any folder.
- Replies (7)
- Open Command Prompt in Folder Using Windows Explorer
- Command Prompt vs PowerShell
- Open Command Prompt Using the Explorer Address Bar
- Adding “Open command window here”
- Opening The Command Prompt Using Windows Explorer
- You’re In Command Now!
How to open a folder in Windows Explorer from VBA?
I want to click a button on my access form that opens a folder in Windows Explorer.
Is there any way to do this in VBA?
11 Answers 11
You can use the following code to open a file location from vba.
You can use this code for both windows shares and local drives.
VbNormalFocus can be swapper for VbMaximizedFocus if you want a maximized view.
The easiest way is
Which only takes one line!
Thanks to PhilHibbs comment (on VBwhatnow’s answer) I was finally able to find a solution that both reuses existing windows and avoids flashing a CMD-window at the user:
where ‘path’ is the folder you want to open.
(In this example I open the folder where the current workbook is saved.)
Pros:
- Avoids opening new explorer instances (only sets focus if window exists).
- The cmd-window is never visible thanks to vbHide.
- Relatively simple (does not need to reference win32 libraries).
Cons:
- Window maximization (or minimization) is mandatory.
Explanation:
At first I tried using only vbHide. This works nicely. unless there is already such a folder opened, in which case the existing folder window becomes hidden and disappears! You now have a ghost window floating around in memory and any subsequent attempt to open the folder after that will reuse the hidden window — seemingly having no effect.
In other words when the ‘start’-command finds an existing window the specified vbAppWinStyle gets applied to both the CMD-window and the reused explorer window. (So luckily we can use this to un-hide our ghost-window by calling the same command again with a different vbAppWinStyle argument.)
However by specifying the /max or /min flag when calling ‘start’ it prevents the vbAppWinStyle set on the CMD window from being applied recursively. (Or overrides it? I don’t know what the technical details are and I’m curious to know exactly what the chain of events is here.)
Here is some more cool knowledge to go with this:
I had a situation where I needed to be able to find folders based on a bit of criteria in the record and then open the folder(s) that were found. While doing work on finding a solution I created a small database that asks for a search starting folder gives a place for 4 pieces of criteria and then allows the user to do criteria matching that opens the 4 (or more) possible folders that match the entered criteria.
Here is the whole code on the form:
The form has a subform based on the table, the form has 4 text boxes for the criteria, 2 buttons leading to the click procedures and 1 other text box to store the string for the start folder. There are 2 text boxes that are used to show the number of folders listed and the number processed when searching them for the criteria.
If I had the Rep I would post a picture. :/
I have some other things I wanted to add to this code but haven’t had the chance yet. I want to have a way to store the ones that worked in another table or get the user to mark them as good to store.
I can not claim full credit for all the code, I cobbled some of it together from stuff I found all around, even in other posts on stackoverflow.
I really like the idea of posting questions here and then answering them yourself because as the linked article says, it makes it easy to find the answer for later reference.
When I finish the other parts I want to add I will post the code for that too. 🙂
Open folder in VS Code from Windows Explorer
While installing the VS Code, we get an option to tick for Open with Code . I gave the tick mark for only files but not for folders. So how to turn it on after installation?
When I’m opening a file:
When I’m opening a folder :
I want the Open with Code option on right-click in the folder just like it shows on files.
2 Answers 2
The answer from @dqureshiumar is correct, if you already checked that option during VS Code installation. But maybe you haven’t checked it and don’t want or can’t reinstall it right now. Or maybe you need more flexibility about the actions shown when right clicking a folder.
So you are able to create your own folder actions at the Windows Registry:
- Press ⊞ Win + R and type regedit .
- Navigate to the path HKEY_CLASSES_ROOT\Directory\shell .
- Right click and create a new Key named vscode .
- At the (Default) REG_SZ , put the desired text, like Open with Code .
- Optionally, create an Icon key pointing to the Code.exe path (most likely «%LocalAppData%\Programs\Microsoft VS Code\Code.exe» ).
At this point, something like this:
Yet inside regedit , go ahead:
- Create another new Key named command inside the vscode one.
- At the (Default) REG_SZ , put the action to open the current path ( «%1» ) based on your Code.exe path (most likely «%LocalAppData%\Programs\Microsoft VS Code\Code.exe» «%1» ).
Now, see something like this:
Finally, go ahead to Windows Explorer and right click any folder:
It’s updated on demand, so you can also play with text, icon and command to try your own custom actions, if you want. The VS Code Command Line Interface reference could be helpful if you want to play with another possibilites, like adding the clicked folder to the current Workspace.
PS.: dealing with regedit can be dangerous. Use it with caution and create a .reg backup before starting if you’re not so experienced on it.
Windows 10 file explorer not opening? Can’t open any folder.
I follow these steps to fix my problem Fix File Explorer if it won’t open or start and I also tried other fixes that is mentioned in other posts but non is working for me.
The last step where it says Run Automatic Repair is only step left.
Can someone tell me why its not opening?
PS: All programs are working fine.
Replies (7)
5 people found this reply helpful
Was this reply helpful?
Sorry this didn’t help.
Great! Thanks for your feedback.
How satisfied are you with this reply?
Thanks for your feedback, it helps us improve the site.
How satisfied are you with this reply?
Thanks for your feedback.
I’m Stefano an Independent Advisor, here to help you.
I would suggest you to uninstall any third party antivirus and perform a clean boot:
Then, if the problem is still showing up, you can perform a repair upgrade:
Once done, perform a disk clean up, if all is working correctly:
1. Open «File Explorer»
2. Click on «This PC»
3. Right click on «C:»
4. Click on «Proprieties»
5. Click on «Clean-up disk»
6. Click on «Clean up system files»
7. Select every option in the list, but not «Download»
8. Click on «OK»
4 people found this reply helpful
Was this reply helpful?
Sorry this didn’t help.
Great! Thanks for your feedback.
How satisfied are you with this reply?
Thanks for your feedback, it helps us improve the site.
How satisfied are you with this reply?
Thanks for your feedback.
2 people found this reply helpful
Was this reply helpful?
Sorry this didn’t help.
Great! Thanks for your feedback.
How satisfied are you with this reply?
Thanks for your feedback, it helps us improve the site.
How satisfied are you with this reply?
Thanks for your feedback.
My name is Andre Da Costa; an Independent Consultant, Windows Insider MVP and Windows & Devices for IT MVP. I’m here to help you with your problem.
Press Windows key + X
Click Windows PowerShell (Admin).
At the command prompt, type the following, hit Enter the restart.
Type in at the prompt OR Copy and Paste these one at a time : (Hit enter after each)
Get-appxpackage -all *shellexperience* -packagetype bundle |%
Press Windows key + X
Click Task Manager
Select the Processes tab
Scroll down to Windows Explorer then select it
Click Restart
If that does not work:
uninstall your display driver:
Press Windows key + X
Click Device Manager
Expand Display adapters
Right click the current display adapter
Click Uninstall
Exit Device Manager
Restart
2. Copy the following text into Notepad:
taskkill /f /im explorer.exe
taskkill /f /im shellexperiencehost.exe
timeout /t 3 /NOBREAK > nul
del %localappdata%\Packages\Microsoft.Windows.ShellExperienceHost_cw5n1h2txyewy\TempState\* /q
timeout /t 2 /NOBREAK > nul
3. Click File and Save.
4. Choose a location to save the file. Enter a File name of ClearTileCache.bat and select Save as type of All files (*.*). Click Save.
5. Open File Explorer and navigate to the location that you chose to save the file to. Double-click ClearTileCache.bat to run the file.
Information in the above link is sourced from a trusted Microsoft MVP blog.
11 people found this reply helpful
Was this reply helpful?
Sorry this didn’t help.
Great! Thanks for your feedback.
How satisfied are you with this reply?
Thanks for your feedback, it helps us improve the site.
How satisfied are you with this reply?
Thanks for your feedback.
Thanks Andre Da Costa,
In option 1 i don’t know when the each code stops cause its all written together.
I did the option 2 and it didn’t work 😌
The option 4 requires me to open file explorer in step 5 which is not working. That’s why i was here.
I will do the option 3 to uninstall my display driver. Hope that works
Was this reply helpful?
Sorry this didn’t help.
Great! Thanks for your feedback.
How satisfied are you with this reply?
Thanks for your feedback, it helps us improve the site.
How satisfied are you with this reply?
Thanks for your feedback.
Hi Onlinewithsherkhan
Greetings! I am Vijay, an Independent Advisor. I am here to work with you on this problem.
To start with, please execute following steps and let me know (You might need to do last point)
1. CTRL+SHIFT+ESC to start Task Manager
Locate Windows Explorer in Processes tab > Right Click > End Task
Now at the top File > Run new task > Put explorer.exe and Enter
2. Run Built-in & Guided Walk through Windows Update troubleshooter
Built-in : Windows Key+X > Click Settings > Click Update & security > Click Troubleshoot > Click Windows Update > Click Run the Troubleshooter
3. Review below Microsoft help
Fix File Explorer if it won’t open or start — https://support.microsoft.com/en-us/help/408737.
4. If nothing works, I would recommend that you perform a Windows 10 repair upgrade. Repair upgrade fixes all Windows errors and retains all files, applications and settings. (You will not lose any data while backup is a good idea) Below is a good guide to perform repair upgrade
Do let me know if you require any further help on this. Will be glad to help you.
Disclaimer — This is a non-Microsoft website. The page appears to be providing accurate, safe information. Watch out for ads on the site that may advertise products frequently classified as a PUP (Potentially Unwanted Products). Thoroughly research any product advertised on the site before you decide to download and install it.
Best regards
Vijay A. Verma @ http://www.eforexcel.com/
Timezone: UTC+05:30, PST+12:30
Availability Hours (UTC) : 05:00 AM — 05:00 PM
Open Command Prompt in Folder Using Windows Explorer
Who wants to type out the full path?
The Command Prompt is an incredibly useful way to perform certain tasks. For example, if you want to run a program with special parameters, the Command Prompt is one fast way to do it. The problem is that navigating the directory structure of a modern computer can be a real pain when using Command Prompt. Especially since Windows 10 supports such long folder and program names.
The good news is that you can open Command Prompt directly from inside a Windows Explorer window. Taking you directly to that folder location!
Command Prompt vs PowerShell
One important point about opening the command prompt in a folder, is that we’re referring specifically to the Windows Command Prompt, rather than PowerShell. Although both programs look similar, being a text-command interface, they are actually very different.
Command Prompt is a simple, lightweight text interface for Windows. In contrast, PowerShell is a complex, powerful command line tool that lets power users do in-depth system management of the computer, among a long list of other handy abilities.
Command Prompt uses the “CMD.exe” while PowerShell uses “powershell.exe”, so they are entirely separate. Although some of the functionality overlaps, the two programs may use different commands to accomplish the same job. This article is only about the Command Prompt, but some of the shortcuts will also work for PowerShell. We’ll indicate when this is the case.
Open Command Prompt Using the Explorer Address Bar
When you open a Windows Explorer folder, you’ll see an address bar similar to that in a web browser. By default, it shows the path of the current folder. You can see it here.
If you click on this address bar, you can type in text. By typing “cmd” and hitting Enter, you’ll open up the command prompt at that location.
This will also work if you type “powershell” instead of “cmd”. Taking you directly to the Windows PowerShell prompt at that folder.
Adding “Open command window here”
In early versions of Windows 10, there was a context menu entry called “Open command window here” which would open the Command Prompt in the folder location you specify. For example, if you right-click on a folder and use this command, the Command Prompt starts at the current folder location.
After the 2017 Creator’s Update for Windows 10, Microsoft removed this option. Why? It’s most likely down to an effort from Microsoft to push people away from using the Command Prompt towards using PowerShell.
Getting this command back is not very difficult, but it does require some tinkering in the Windows Registry. If you don’t feel comfortable doing that, it’s best to skip this method, but if you really want that context menu option back, here’s what to do.
First, click Start and type regedit. Then click on the regedit program entry.
With the registry editor open, look for the following registry key at this path:
HKEY_CLASSES_ROOT\Directory\shell\cmd
This is where things might start to feel a little risky, but we aren’t doing anything that will break your computer. But make sure you follow these exact instructions!
Right-click on the key and click Permissions in the context menu.
In the dialogue box that opens up, click Advanced.
At the top of the advanced settings window, you’ll see the listed owner of the key. Click the Change option.
Next, type your username and then click check names to validate it. Then click OK.
Finally, make sure the Replace owner on subcontainers and objects box is selected before clicking OK.
Now we’re back on the permissions page. Select Administrators under Group or user names and select Allow next to Full control. Then click OK.
Now we have to restore the context menu entry for the Command Prompt.
Back inside the CMD window, all we have to do is change the “DWORD” from “HideBasedOnVelocityiD” to “ShowBasedOnVelocityId”. Just right-click on it and choose rename, then change the name of the DWORD.
If all has gone as planned, you should now see the “Open command window here” option, when you SHIFT+right-click an item in the Windows Explorer window.
Opening The Command Prompt Using Windows Explorer
This next method of opening the Command Prompt from a Windows Explorer window involves navigating to where the Command Prompt program itself is stored and running it directly from there. This is still useful when, for one reason or another, other means of opening Command Prompt don’t work.
You can find “cmd.exe” in C:\Windows\System32. If you want to run it with administrative privileges, simply right-click cmd.exe and choose Run as administrator. There are plenty of commands that require administrative privileges to work and this is one of the ways you can start the Command Prompt with those privileges without leaving Explorer.
You’re In Command Now!
As they;ve done with HyperTerminal, Microsoft may choose to one day completely phase out Command Prompt, in favor of PowerShell. While that’s not a bad thing in itself, PowerShell could do with some polish to help non-power users who would have been fine with the Command Prompt to use common functions just as easily. Still, until the day Command Prompt actually does go the way of the Dodo, you can rest assured it’s only a few clicks away.
If you need to improve your Command Prompt skills, then why not check out these 21 commands that every Windows user should know. You’ll be flying through tasks in no time armed with these incredibly useful tricks.
Sydney Butler is a social scientist and technology fanatic who tries to understand how people and technology coexist. He has two decades of experience as a freelance computer technician and more than a decade as a technologies researcher and instructor. Sydney has been a professional technology writer for more than five years and covers topics such as VR, Gaming, Cyber security and Transhumanism. Read Sydney’s Full Bio