您好我已经创建了一个VBA宏,每行创建一个xml文件。问题是在默认文件夹位置创建的xml文件" C:\ Users \ Dell \ Documents"如何更改默认的输出目录?
EVALUATE
FILTER(
SUMMARIZE(
'Fact Table',
FieldTable[Field1],
'Metric1',
CALCULATE(
[MetricA]
FILTER(
'Fact Table'
[MetricA],
[Year] = 2017
)
) + 0,
'Metric2',
CALCULATE(
[MetricB]
FILTER(
'Fact Table'
[MetricA],
[Year] = 2016
)
)
),
[Metric1]<>0
)
答案 0 :(得分:0)
基于斯科特的评论,这里是经过调整的答案:
Sub xmlPerRow()
sTemplateXML = _
"<?xml version='1.0'?>" + vbNewLine + "<data>" + vbNewLine + "<Grai>" + vbNewLine + "</Grai>" + vbNewLine + _
" <DayDateOut>" + vbNewLine + " </DayDateOut>" + vbNewLine + " <Filler>" + vbNewLine + " </Filler>" + vbNewLine + _
" <FillerCountry>" + vbNewLine + " </FillerCountry>" + vbNewLine + " <Retailer>" + vbNewLine + " </Retailer>" + vbNewLine + _
" <RetailerCountry>" + vbNewLine + " </RetailerCountry>" + vbNewLine + " <Days>" + vbNewLine + " </Days>" + vbNewLine + _
" <DayBack>" + vbNewLine + " </DayBack>" + vbNewLine + " <DateIn>" + vbNewLine + " </DateIn>" + vbNewLine + _
" <BrokenCode>" + vbNewLine + " </BrokenCode>" + vbNewLine + " <Broken>" + vbNewLine + " </Broken>" + vbNewLine + _
" <TotalCycles>" + vbNewLine + " </TotalCycles>" + vbNewLine + "</data>" + vbNewLine
Set doc = CreateObject("MSXML2.DOMDocument")
doc.async = False
doc.validateOnParse = False
doc.resolveExternals = False
With ActiveWorkbook.Worksheets(1)
lLastRow = .UsedRange.Rows.Count
For lRow = 2 To lLastRow
sFile = "c:\GraiData\Grai_" & .Cells(lRow, 1).Value & ".xml"
Dim sGrai As String
sGrai = CStr(.Cells(lRow, 1).Value)
sDayDateOut = .Cells(lRow, 2).Value
sFiller = .Cells(lRow, 3).Value
sFillerCountry = .Cells(lRow, 4).Value
sRetailer = .Cells(lRow, 5).Value
sRetailerCountry = .Cells(lRow, 6).Value
sDays = .Cells(lRow, 7).Value
sDayBack = .Cells(lRow, 8).Value
sDateIn = .Cells(lRow, 9).Value
sBrokenCode = .Cells(lRow, 10).Value
sBroken = .Cells(lRow, 11).Value
sTotalCycles = .Cells(lRow, 12).Value
doc.LoadXML sTemplateXML
doc.getElementsByTagName("Grai")(0).appendChild doc.createTextNode(sGrai)
doc.getElementsByTagName("DayDateOut")(0).appendChild doc.createTextNode(sDayDateOut)
doc.getElementsByTagName("Filler")(0).appendChild doc.createTextNode(sFiller)
doc.getElementsByTagName("RetailerCountry")(0).appendChild doc.createTextNode(sRetailerCountry)
doc.getElementsByTagName("Retailer")(0).appendChild doc.createTextNode(sRetailer)
doc.getElementsByTagName("Days")(0).appendChild doc.createTextNode(sDays)
doc.getElementsByTagName("DayBack")(0).appendChild doc.createTextNode(sDayBack)
doc.getElementsByTagName("DateIn")(0).appendChild doc.createTextNode(sDateIn)
doc.getElementsByTagName("BrokenCode")(0).appendChild doc.createTextNode(sBrokenCode)
doc.getElementsByTagName("Broken")(0).appendChild doc.createTextNode(sBroken)
doc.getElementsByTagName("TotalCycles")(0).appendChild doc.createTextNode(sTotalCycles)
doc.Save sFile
Next
End With
End Sub