Visual Basic in Excel 2007 FFH-Editor

Rod

King
Joined
Sep 22, 2004
Messages
754
Location
Munich / Germany
Hi,

yesterday I tried my hands firsttime one the Visual Basic of Excel 2007 in the FFH-Editor. The reason is that I want to edit the script 14 for Diplomacy screen.

I am adding 6 leaders for a personal scenario and even when you can easily do the same in the most sheets the Diplomacy screen is giving a problem.

I explain it briefly. The most table sheets are counting columns (every column has a '1' written in one row). Therefore you can easily add new columns because they get counted as well.

But the diplomacy table sheet is working different. It still using columns and counts them, but the the leaders are listed in rows (rows do not get counted).
Therefore the script is hardcoded on terms of rows (but uses variables for the columns). So far so easy.
The easy way out to add 6 leaders is simply to change the rows in the script (simply add 6 to all entries).

I show what I mean :

Spoiler :

Original Code :
For j = 5 To 36
If Cells(j, i) <> "" Then
Print #1, " <Response>"
Print #1, " <Civilizations/>"
Print #1, " <Leaders>"
Print #1, " <Leader>"
Print #1, " <LeaderType>" & Cells(j, 1) & "</LeaderType>"
Print #1, " <bLeaderType>1</bLeaderType>"
Print #1, " </Leader>"
Print #1, " </Leaders>"
Print #1, " <Attitudes>"

New Code :
For j = 5 To 42
If Cells(j, i) <> "" Then
Print #1, " <Response>"
Print #1, " <Civilizations/>"
Print #1, " <Leaders>"
Print #1, " <Leader>"
Print #1, " <LeaderType>" & Cells(j, 1) & "</LeaderType>"
Print #1, " <bLeaderType>1</bLeaderType>"
Print #1, " </Leader>"
Print #1, " </Leaders>"
Print #1, " <Attitudes>"


you get the idea.

The other way is to add a row counter in Cell B4 (Cells(4,2)) :

Spoiler :

Private Sub CommandButton1_Click()
'
Dim i, j As Integer
'
Open ThisWorkbook.Path & "/Assets/xml/gameinfo/CIV4DiplomacyInfos.xml" For Output As #1
'
Print #1, "<?xml version=""1.0""?>"
Print #1, "<!-- Created with the FfH editor by Kael-->"
Print #1, "<!-- Sid Meier's Civilization 4 -->"
Print #1, "<!-- Copyright Firaxis Games 2005 -->"
Print #1, "<!-- -->"
Print #1, "<!-- Diplomacy Infos -->"
Print #1, "<Civ4DiplomacyInfos xmlns=""x-schema:CIV4GameInfoSchema.xml"">"
Print #1, " <DiplomacyInfos>"
'
For i = 2 To Cells(1, 3) + 1
'
If Cells(2, i) <> Cells(2, i - 1) Then
Print #1, " <DiplomacyInfo>"
j = 2
Print #1, " <" & Cells(j, 1) & ">" & Cells(j, i) & "</" & Cells(j, 1) & ">"
Print #1, " <Responses>"
End If
'
For j = 5 To Cells(4, 2) + 4
If Cells(j, i) <> "" Then
Print #1, " <Response>"
Print #1, " <Civilizations/>"
Print #1, " <Leaders>"
Print #1, " <Leader>"
Print #1, " <LeaderType>" & Cells(j, 1) & "</LeaderType>"
Print #1, " <bLeaderType>1</bLeaderType>"
Print #1, " </Leader>"
Print #1, " </Leaders>"
Print #1, " <Attitudes>"
'
For k = Cells(4, 2) + 6 To Cells(4, 2) + 10
If Cells(k, i) <> "" Then
Print #1, " <Attitude>"
Print #1, " <AttitudeType>" & Cells(k, 1) & "</AttitudeType>"
Print #1, " <bAttitudeType>1</bAttitudeType>"
Print #1, " </Attitude>"
End If
Next
'
Print #1, " </Attitudes>"
Print #1, " <DiplomacyPowers>"
'
For k = Cells(4, 2) + 12 To Cells(4, 2) + 14
If Cells(k, i) <> "" Then
Print #1, " <DiplomacyPower>"
Print #1, " <DiplomacyPowerType>" & Cells(k, 1) & "</DiplomacyPowerType>"
Print #1, " <bDiplomacyPowerType>1</bDiplomacyPowerType>"
Print #1, " </DiplomacyPower>"
End If
Next
'
Print #1, " </DiplomacyPowers>"
Print #1, " <DiplomacyText>"
Print #1, " <Text>" & Cells(j, i) & "</Text>"
Print #1, " </DiplomacyText>"
Print #1, " </Response>"
End If
Next
'
If Cells(Cells(4, 2) + 16, i) <> "" Then
Print #1, " <Response>"
Print #1, " <Civilizations/>"
Print #1, " <Leaders/>"
Print #1, " <Attitudes>"
'
For j = Cells(4, 2) + 6 To Cells(4, 2) + 10
If Cells(j, i) <> "" Then
Print #1, " <Attitude>"
Print #1, " <AttitudeType>" & Cells(j, 1) & "</AttitudeType>"
Print #1, " <bAttitudeType>1</bAttitudeType>"
Print #1, " </Attitude>"
End If
Next
'
Print #1, " </Attitudes>"
Print #1, " <DiplomacyPowers>"
'
For j = Cells(4, 2) + 12 To Cells(4, 2) + 14
If Cells(j, i) <> "" Then
Print #1, " <DiplomacyPower>"
Print #1, " <DiplomacyPowerType>" & Cells(j, 1) & "</DiplomacyPowerType>"
Print #1, " <bDiplomacyPowerType>1</bDiplomacyPowerType>"
Print #1, " </DiplomacyPower>"
End If
Next
'
Print #1, " </DiplomacyPowers>"
Print #1, " <DiplomacyText>"
'
For j = Cells(4, 2) + 16 To Cells(4, 2) + 30
If Cells(j, i) <> "" Then
Print #1, " <Text>" & Cells(j, i) & "</Text>"
End If
Next
Print #1, " </DiplomacyText>"
Print #1, " </Response>"
End If
'
If Cells(2, i + 1) <> Cells(2, i) Then
Print #1, " </Responses>"
Print #1, " </DiplomacyInfo>"
End If
Next
'
'
'
Print #1, " </DiplomacyInfos>"
Print #1, "</Civ4DiplomacyInfos>"
'
Close #1
'
End Sub


I have not tested this last script, it was just an idea.

But the problem is not to change the code, but as soon as I want to execute the script it gives me an error that Private Sub CommandButton1_Click() can not be compiled because it is not found in the library.
Certainly I am just missing the libraries for Excel 2007, the question is now what do I have to install/activate (whatever) in Excel 2007 to execute VBA scripts like the ones used for FFH-Editor XML-Export-scripts ???
 
Top Bottom