Refresh destination folder

2Took

Board Regular
Joined
Jun 13, 2022
Messages
203
Office Version
  1. 365
Platform
  1. Windows
Macro saves Excel file to a folder, but in order to see that file saved in File Explorer -- have to hit refresh button on it.

How to refresh destination folder via VBA?
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
One workaround is to open a new instance of Windows explorer after you do the save, using VBA.

VBA Code:
Option Explicit

'Need this at top of module:
#If VBA7 Then
   Declare PtrSafe Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As LongPtr, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As LongPtr
#Else
   Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
#End If

'Open explorer at specified folder
Sub ExploreFolder(path)
    ShellExecute 0, "open", path, 0, 0, 1
End Sub

Sub Demo()
    ExploreFolder Environ("Temp")
End Sub
 
Upvote 0
Where do I tell it the folder I need opened?
Do I need both of those subs?
 
Upvote 0
1. The variable "path".
2. No, just Sub ExploreFolder
 
Upvote 0
1. The variable "path".
2. No, just Sub ExploreFolder
1. so, to replace "path" just in this
VBA Code:
Sub ExploreFolder(path)
line of code, leave word "path" in the
Code:
ShellExecute 0, "open", path, 0, 0, 1
?
And it will close if that folder is already opened, then reopen it?
 
Upvote 0
Use it as per example below:

VBA Code:
Sub Example()
    Dim MyPath As String
    
    MyPath = "C:\WINDOWS\system32"        'valid folder name
    
    ExploreFolder MyPath
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,171
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