我正在尝试使用VBA和RegExp从Excel Power Query外部数据源中提取数据源文件名。
WorkbookQuery公式如下:
let
Source = Excel.Workbook(File.Contents("G:\ExecutiveReporting\Main Reports\Source Queries - Last Quarter.xlsm"), null, true),
Shortages_Sheet = Source{[Item="Shortages",Kind="Sheet"]}[Data],
#"Promoted Headers" = Table.PromoteHeaders(Shortages_Sheet, [PromoteAllScalars=true]),
#"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"Location #", Int64.Type}, {"Shortage Date", Int64.Type}, {"Due Date", Int64.Type}, {"Shortage Type", Int64.Type}, {"Over/Short", Int64.Type}, {"Overdue?", Int64.Type}, {"Lot Count", Int64.Type}})
in
#"Changed Type"
我需要检索“ G:\ ExecutiveReporting \ Main Reports \源查询-Last Quarter.xlsm”
这需要对可能具有不同数据源的多个工作簿查询进行。
Public Function ExtractFilename( _
strInput As String _
) As String
Dim _
regEx As New RegExp, _
strPattern As String, _
strResult As String, _
mcoll As MatchCollection, _
mtch As Match
strPattern = "[NEED THE PATTERN HERE]"
With regEx
.MultiLine = True
.IgnoreCase = True
.Pattern = strPattern
End With
Set mcoll = regEx.Execute(strInput)
End Function