最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

VBA Excel - Using SHELL for opening the location folder and selecting the active file does not works when folder name have a Com

programmeradmin4浏览0评论

I am trying to use the following syntax to open the active workbook Location and select the file at the same time:

Shell "C:\Windows\explorer.exe /select," & location, vbMaximizedFocus

Where location is the path for the active workbook

It works perfectly except when the folder that I am trying to open contains a comma on its name.

For instance: C:\Users\q1Bossymess\CpSolution\CpSolution - Fairgrounds\06-2025 FY\Reports, Clinical\08.25.24 AaSS.xlsx

If I copy the whole path and paste it in the address bar of Windows Explorer, it opens the folder without any problem

The problem starts when I try to use the Shell Statement.

If I rename the target folder with the comma from "Reports, Clinical" to something else, everything works perfectly.

I can't change the name of the folders because I am building an Add-in that is going to be used for different people in different computers and it needs to work every single time on all circumstances.

Thanks.

I just found what the problem is by changing the name of the Folder to detect the problem. It works perfect when the folder name has a "&" or "-" but does not works with commas in the folder name.

My expectation is to be able to open any folder and highlight the active workbook on Windows Explorer, which works great except the comma issue.

I am trying to use the following syntax to open the active workbook Location and select the file at the same time:

Shell "C:\Windows\explorer.exe /select," & location, vbMaximizedFocus

Where location is the path for the active workbook

It works perfectly except when the folder that I am trying to open contains a comma on its name.

For instance: C:\Users\q1Bossymess\CpSolution\CpSolution - Fairgrounds\06-2025 FY\Reports, Clinical\08.25.24 AaSS.xlsx

If I copy the whole path and paste it in the address bar of Windows Explorer, it opens the folder without any problem

The problem starts when I try to use the Shell Statement.

If I rename the target folder with the comma from "Reports, Clinical" to something else, everything works perfectly.

I can't change the name of the folders because I am building an Add-in that is going to be used for different people in different computers and it needs to work every single time on all circumstances.

Thanks.

I just found what the problem is by changing the name of the Folder to detect the problem. It works perfect when the folder name has a "&" or "-" but does not works with commas in the folder name.

My expectation is to be able to open any folder and highlight the active workbook on Windows Explorer, which works great except the comma issue.

Share Improve this question edited 2 days ago Gixman asked 2 days ago GixmanGixman 33 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

Quote the path:

Shell "C:\Windows\explorer.exe /select,""" & location & """", vbMaximizedFocus

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论