VBA 符号 - 引号中的反斜杠
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23529017/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
VBA notation - backslash in quotations
提问by PerfectContrast
A colleague at work made a macro and I need to edit it, but first I need to figure out how it works.
一位同事在工作中制作了一个宏,我需要对其进行编辑,但首先我需要弄清楚它是如何工作的。
Sheet2.Pictures.Insert(importPath & "\" & partName & "\" & picName & ".png").Select
This line is (I think) where images are inserted into the excel document. I'm trying to figure out exactly how it works. I know importpath, partName and picName are variables he defined earlier. importPath is self explanatory, I don't know why part name is in there but I know what it is and picName is there because you enter the picture name in a certain cell and it searches for that name in the importPath to insert into the sheet.
这一行(我认为)是将图像插入到 excel 文档中的位置。我试图弄清楚它到底是如何工作的。我知道 importpath、partName 和 picName 是他之前定义的变量。importPath 是不言自明的,我不知道为什么部分名称在那里,但我知道它是什么并且 picName 在那里,因为您在某个单元格中输入图片名称并在 importPath 中搜索该名称以插入到工作表中.
Also what confuses me is the & and "\" I have no idea what these do.
另外让我感到困惑的是 & 和 "\" 我不知道它们是做什么的。
Any help out there?
有什么帮助吗?
回答by Alex McMillan
This is compiling a group of variables into a String that represents a path. For example, if:
这是将一组变量编译成一个表示路径的字符串。例如,如果:
importPath = "myPics"
partName = "2014"
picName = "flower"
Then the line
然后线
importPath & "\" & partName & "\" & picName & ".png"
will create the String
将创建字符串
"myPics14\flower.png"
which is the full filename being passed to Sheet2.Pictures.Insert
这是传递给的完整文件名 Sheet2.Pictures.Insert
回答by Phil.Wheeler
You're constructing a full file path to an image in that line so the &
concatenates all the string variables and the "\"
is just manually adding the backslash characters you'd expect to see in any windows explorer or command line window.
您正在构建该行中图像的完整文件路径,以便&
连接所有字符串变量,并且"\"
只是手动添加您希望在任何 Windows 资源管理器或命令行窗口中看到的反斜杠字符。