Hello,
Hi Rabi,
Hi Emily,
Hi Rabi,
Hello Taylor,
' ============================================
' Instantiate objects
'
============================================
If Not IsObject(LEAP) Then
set LEAP =
CreateObject("Leap.LEAPApplication")
End If
set xla =
CreateObject("Excel.Application")
' ============================================
dim tech_branches
set tech_branches =
CreateObject("Scripting.Dictionary")
'dim tagnames, taggroups As
String
for each b in LEAP.Branches
if b.Branchtype = 4 then
tech_branches.Add b.BranchID,
b.Name
end if
next
xla.Visible = false
xla.ScreenUpdating = true
set xlw = xla.Workbooks.Add
LEAP.Verbose = 4
LEAP.Visible = true
set xls = xla.sheets.add
xls.name = "Exported from
LEAP"
' Add headers to Excel worksheet
r = 1
xls.Cells(r, 1).Value =
"Scenario"
xls.Cells(r, 2).Value = "Year"
xls.Cells(r, 3).Value =
"Branch"
xls.Cells(r, 4).Value =
"Region"
xls.Cells(r, 5).Value =
"Fuel"
xls.Cells(r, 6).Value =
"Value (MMBtu)"
xls.Cells(r, 7).Value =
"Tag (Name)"
xls.Cells(r, 8).Value =
"Tag (Group)"
LEAP.ActiveView =
"Results"
' Loop through scenarios, years,
branches and export final energy demand in gigajoules
for each s in LEAP.Scenarios
for y = LEAP.BaseYear to
LEAP.EndYear
for each key in
tech_branches.keys
for i = 1 to leap.regions.count
r = r + 1
xls.Cells(r, 1).Value = s
xls.Cells(r, 2).Value = y
xls.Cells(r, 3).Value =
LEAP.Branch(key).FullName
xls.Cells(r, 4).Value =
LEAP.Regions(i).Name
xls.Cells(r, 5).Value =
LEAP.Branch(key).Fuel.Name
xls.Cells(r, 6).Value =
LEAP.Branch(key).Variable("Energy Demand Final Units").Value(y,
"Million BTU")
for each t in
LEAP.Branch(key).Tags
tagnames = t.Name & ",
" & tagnames
taggroups = t.TagGroup.Name
& ", " & taggroups
next
xls.Cells(r, 7).Value = tagnames
xls.Cells(r, 8).Value =
taggroups
tagnames = ""
taggroups = ""
next
next
next
next
xla.screenupdating = true
xla.visible = true
LEAP.ActiveView =
"Analysis"
Hi Rabi, sorry for the wait.
HI Taylor and Emily,
I'm following up on
Rabi's code questions, working on the same issue.
Your help was much
appreciated but now we're running in to two issues.
Thank you very much.
The code is pasted below. I have added line numbers, please let me know if you'd like the code without them. Additionally, you'll see that we've temporarily commented out all of our tag work-- that's something we can do with equations in excel, and we wanted to minimize the possible areas for error while trouble shooting.
Thanks,
Kate
1' ============================================
2 ' Instantiate objects
3' ============================================
4 If Not IsObject(LEAP) Then
5 set LEAP = CreateObject("Leap.LEAPApplication")
6 End If
7
8 set xla = CreateObject("Excel.Application")
9 ' ============================================
10
11 dim tech_branches
12 set tech_branches = CreateObject("Scripting.Dictionary")
13 'dim tagnames, taggroups As String
14
15 For i = 1 to Leap.Regions.Count
16 Leap.Regions(i).Active = True
17 V = Leap.Regions(i).Active
18 tech_branches.RemoveAll
19 for each b in LEAP.Branches
20 if b.Branchtype = 4 then
21 tech_branches.Add b.BranchID, b.Name
22 end if
23 next
24
25 xla.Visible = false
26 xla.ScreenUpdating = true
27
28 set xlw = xla.Workbooks.Add
29
30 LEAP.Verbose = 4
31 LEAP.Visible = true
32
33 set xls = xla.sheets.add
34 xls.name = "Exported from LEAP"
35
36 ' Add headers to Excel worksheet
37 r = 1
38 xls.Cells(r, 1).Value = "Scenario"
39 xls.Cells(r, 2).Value = "Year"
40 xls.Cells(r, 3).Value = "Branch"
41 xls.Cells(r, 4).Value = "Region"
42 xls.Cells(r, 5).Value = "Fuel"
43 xls.Cells(r, 6).Value = "Value (MMBtu)"
44 xls.Cells(r, 7).Value = "Tag (Name)"
45 xls.Cells(r, 8).Value = "Tag (Group)"
46
47 LEAP.ActiveView = "Results"
48
49 ' Loop through scenarios, years, branches and export final energy demand in gigajoules
50 For each s in Leap.Scenarios.Count
51 LEAP.Scenarios(s).Active = true
52 for y = LEAP.BaseYear to LEAP.EndYear
53 for each key in tech_branches.keys
54
55 r = r + 1
56 xls.Cells(r, 1).Value = s
57 xls.Cells(r, 2).Value = y
58 xls.Cells(r, 3).Value = LEAP.Branch(key).FullName
59 xls.Cells(r, 4).Value = LEAP.Regions(i).Name
60 xls.Cells(r, 5).Value = LEAP.Branch(key).Fuel.Name
61 xls.Cells(r, 6).Value = LEAP.Branch(key).Variable("Energy Demand Final Units").Value(y, "Million BTU")
62
63 'for each t in LEAP.Branch(key).Tags
64 'tagnames = t.Name & ", " & tagnames
65 'taggroups = t.TagGroup.Name & ", " & taggroups
66 'next
67
68 'xls.Cells(r, 7).Value = tagnames
69 'xls.Cells(r, 8).Value = taggroups
70 'tagnames = ""
71 'taggroups = ""
72
73 next
74 next
75 next
76 next
77
78 xla.screenupdating = true
79 xla.visible = true
80 LEAP.ActiveView = "Analysis"