当工作簿名称包含空格时,在Excel VBA中使用Application.Run [英] Using Application.Run in Excel VBA when workbook name contains spaces

查看:258
本文介绍了当工作簿名称包含空格时,在Excel VBA中使用Application.Run的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Application.RunMyWorkBook.xls!Macro1

Application.Run "MyWorkBook.xls!Macro1"

将工作(在MyWorkBook.xls文件中运行名为Macro1的宏)

will work (run the macro called Macro1 in the MyWorkBook.xls file)

Application.Run "My Work Book.xls!Macro1"

不会(如果工作簿名称包含空格,Excel表示无法找到宏)。

will not (if the workbook name contains spaces, Excel says "the macro cannot be found").

我刚刚花了几个小时弄清楚这是造成这个问题的空格...

I just spent hours figuring out that it's the spaces causing this problem...

在没有重命名文件的情况下有没有办法?

推荐答案

使用文件名中的单引号:

Use single quotes surrounding the filename:

Application.Run "'My Work Book.xls'!Macro1"

这篇关于当工作簿名称包含空格时,在Excel VBA中使用Application.Run的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆