98.7% Of all customers recommend us, we're so confident about our results we publish all reviews and stats
View Live Stats View ReviewsForum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Refresh windows file explorer window from Excel VBA
Refresh windows file explorer window from Excel VBA
Resolved · Low Priority · Version 2016
Jon has attended:
Excel VBA Introduction course
Excel VBA Intermediate course
Effective Communication Skills course
Power BI Modelling, Visualisation and Publishing course
Refresh windows file explorer window from Excel VBA
Hello,
Do you know of any way to refresh a Windows file explorer window from Excel through VBA?
Thanks,
Jon
RE: Refresh windows file explorer window from Excel VBA
Hi Jon,
Thank you for the forum question.
I am not sure what you want. Please let me know which file you want to refresh and why?
You can use the FileSystem object to control files and folders.
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
RE: Refresh windows file explorer window from Excel VBA
Hi Jens,
I want to refresh the view in Windows File Explorer after processing files through Excel VBA and saving from a Remote Desktop to my work server.
Effectively it's just tidy up the view, removing the temp Excel file (beginning with ~$). It's the equivalent of pressing 'F5' in File Explorer.
Any thoughts?
Thanks,
Jon
RE: Refresh windows file explorer window from Excel VBA
Hi Jon,
Please try the code below and please let me know if it is not doing what you want.
Sub RefreshMyfolder()
Dim oShellObject
Set oShellObject = CreateObject("Wscript.Shell")
strFolder = "C:\folder to refresh path"
oShellObject.AppActivate strFolder
oShellObject.SendKeys "{F5}"
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
RE: Refresh windows file explorer window from Excel VBA
Hi Jens,
Thanks so much for your reply.
This seems to open the 'Go To' dialogue box in Excel (shortcut key F5).
Does this mean the SendKeys command is somehow being applied to Excel instead of Windows through the 'Wscript.Shell' object?
Many thanks,
Jon
RE: Refresh windows file explorer window from Excel VBA
Hi Jon,
I will do some research and come back to you later today.
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
RE: Refresh windows file explorer window from Excel VBA
Hi Jon,
Sub RefreshMyFiles()
Dim wsh
Set wsh = VBA.CreateObject("WScript.Shell")
Dim waitOnReturn As Boolean
waitOnReturn = True
Dim windowStyle As Integer
windowStyle = 0 'windowStyle = 1 when visible
Dim OpenFolder As String
OpenFolder = "C:\Users\Jens\Desktop\Excel Advanced"
wsh.Run "%windir%\explorer.exe /n," & OpenFolder, windowStyle, waitOnReturn
wsh.AppActivate OpenFolder
wsh.SendKeys "{F5}"
Set wsh = Nothing
End Sub
This code I have tested and it works fine on my laptop. Please let me know if it is not working for you.
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
RE: Refresh windows file explorer window from Excel VBA
Hi Jens,
I'm terribly sorry but this still opens the Excel 'Go To' dialogue without refreshing my folder in Windows.
Could it be a version issue perhaps? I'm using Windows 10 Pro 64 with Office 365 for Business.
Many thanks,
Jon
RE: Refresh windows file explorer window from Excel VBA
Hi Jon,
Sorry then I really do not know how to help you. Both codes I have sent you are working on my computer and also this is the code I could find on the all the websites I have been looking at today to find a solution.
The version doesn't matter. I'm using Windows 10 Pro 64 with Office 2019 for Business. VBA is always backward compatible.
The line below will activate the folder you want to refresh but this is the line which are not working for you:
wsh.AppActivate OpenFolder
and in the first code:
oShellObject.AppActivate strFolder
If the Excel file is active when the reach the SendKey line you will get the Goto dialog box.
I am sorry I cannot really do more.
You can try to step the code and just before the SendKey line manually activate the folder. Of course this will not explain why the code is not working.
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
RE: Refresh windows file explorer window from Excel VBA
Hi Jens,
No problem, thanks for your help today, much appreciated.
I'll play around with the code and let you know if I discover anything interesting.
Thanks again and best wishes :)
Jon
RE: Refresh windows file explorer window from Excel VBA
Hi Jon,
You are welcome.
I will come back to you if I get an idea.
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
Wed 12 Jun 2019: Automatically marked as resolved.
Training information:
Welcome. Please choose your application (eg. Excel) and then post your question. Our Microsoft Qualified trainers will then respond within 24 hours (working days). Frequently Asked Questions
Any suggestions, questions or comments? Please post in the Improve the forum thread. |
Excel tip:Select only cell that contain text to lock formatFor selecting cells that only contain Text in Excel |