excel - Print path of input file
问题描述
I have developed a macro that imports to my main workbook some data from other workbooks, which are stored in different folders, and keeps the link instead of doing the simplye copy-paste xlvalues. Thereby an extract of the code
With Master.Sheets("Sheet1")
.Activate
.Range("F4").Select
.Paste Link:=True
End With
In this way, the cells of the workbook "Master" display the link, for example:
"'C:\Users\Documents\[Input.xlsx]Sheet1'!E29"
Is there a macro code which would allow me to extract from the abovementioned link only the path to the relevant workbook (i.e. 'C:\Users\Documents\[Input.xlsx]
) so that I can print it in a summary report to display the path of the inputs?
解决方案
Please, try the next piece of code:
Sub extractPathFromLink()
Dim x As String, path As String
x = "'C:\Users\Documents\[Input.xlsx]Sheet1'!E29"
path = Split(Split(x, "'")(1), "]")(0) & "]"
MsgBox path
End Sub
Edited:
The next version returns the real workbook path:
Sub extractPath()
Dim x As String, path As String
x = "'C:\Users\Documents\[Input.xlsx]Sheet1'!E29"
path = Replace(Split(Split(x, "'")(1), "]")(0), "[", "")
MsgBox path
End Sub
推荐阅读
- python - 具有命名索引的布尔子集
- vue.js - 在 vue 子组件中建立初始值
- azure - 删除 Azure 恢复服务保管库时收到错误
- apache-kafka-streams - Kafka Streams Processor API 按大小和时间进行批处理
- c# - 在 MacOS 上构建 Unity3D 问题
- java - 使用外部方法更改设置后如何更新设置显示
- c# - 从一个字典和第二个字典中选择
- pdf - Win 10 上的 Adobe PDF Ifilter 11 和 9 无法正常工作
- angular - Angular登录令牌并同步获取用户数据
- security - 我的 redux 状态变量是否容易被愤怒的员工提取?没有 api 调用或 AsyncStorage