Clever-Excel-Forum

Normale Version: VBA Textexport mit Zelleninhalten
Du siehst gerade eine vereinfachte Darstellung unserer Inhalte. Normale Ansicht mit richtiger Formatierung.
Seiten: 1 2 3
Hallo,

ich bin jetzt schon ca. 12h am basteln und komm nicht mehr weiter. Ich hoffe, Ihr könnt mir bei meinem Problem helfen.

Ich habe ein Excel-VBA geschrieben, welches mehrere Textdateien einließt und diese dann in verschiedene Spalten einträgt.

Ziel ist es, den Inhalt einzelner Spalten in verschiedenen Zeilen in ein Textdokument zu exportieren. Hinzu kommt noch,
dass der Aufbau des Dokumentes in abhängigkeit der gefüllten Spalten variiert.

Das Ganze ist so aufgebaut.... Ich lese Parameterdateien ein, in welcher z.B. in Zeile B4 eine Geokoordinate steht. Je nach Anzahl
der eingelesenen Textdateien können dies 1-50 Stück sein. Dies soll das Programm erkennen und die Textdatei wie folgt aufbauen:

Ziel ist es, aus der Textdatei eine KML-Datei für Google-Earth zu erstellen:


Code:
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2" xmlns:kml="http://www.opengis.net/kml/2.2" xmlns:atom="http://www.w3.org/2005/Atom">
<Document>
    "<name>Export.kml</name>                                                               <------ Inhalt der Zeile 2 in Spalte 1
   <StyleMap id="m_ylw-pushpin">
       <Pair>
         <key>normal</key>
            <styleUrl>#s_ylw-pushpin</styleUrl>
       </Pair>
        <Pair>
       <key>highlight</key>
        <styleUrl>#s_ylw-pushpin_hl</styleUrl>
  </Pair>
    </StyleMap>
   <Style id="s_ylw-pushpin_hl">
       <IconStyle>
            <scale>1.3</scale>
            <Icon>
                <href>http://maps.google.com/mapfiles/kml/pushpin/ylw-pushpin.png</href>
            </Icon>
            <hotSpot x="20" y="2" xunits="pixels" yunits="pixels"/>
        </IconStyle>
    </Style>
    <Style id="s_ylw-pushpin">
        <IconStyle>
            <scale>1.1</scale>
            <Icon>
                <href>http://maps.google.com/mapfiles/kml/pushpin/ylw-pushpin.png</href>
            </Icon>
            <hotSpot x="20" y="2" xunits="pixels" yunits="pixels"/>
        </IconStyle>
    </Style>
    <Folder>
        <name>Export</name>
        <open>1</open>
        <Placemark>
            <name>erste Koordinate</name>                                                                    <------ Inhalt der Zeile 4 in Spalte 1
            <LookAt>
                <longitude>8.705635191505049</longitude>                                             <------ Inhalt der Zeile 5 in Spalte 1
                <latitude>49.1001516022849</latitude>                                                     <------ Inhalt der Zeile 6 in Spalte 1
                <altitude>0</altitude>
                <heading>-1.42700672357499e-005</heading>
                <tilt>0</tilt>
                <range>388.3069813372824</range>
                <gx:altitudeMode>relativeToSeaFloor</gx:altitudeMode>
            </LookAt>
            <styleUrl>#m_ylw-pushpin</styleUrl>
            <Point>
                <gx:drawOrder>1</gx:drawOrder>
                <coordinates>8.705635191505047,49.10015160228491,0</coordinates>   <------ Inhalt der Zeilen 5+6 in Spalte 1
            </Point>
        </Placemark>
        <Placemark>
            <name>zweite Koordinate</name>                                                                  <------ Inhalt der Zeile 4 in Spalte 2    usw. usw.
            <LookAt>
                <longitude>8.705777196688841</longitude>
                <latitude>49.10006120849889</latitude>
                <altitude>0</altitude>
                <heading>9.306514354730476e-005</heading>
                <tilt>0</tilt>
                <range>388.7695146071881</range>
                <gx:altitudeMode>relativeToSeaFloor</gx:altitudeMode>
            </LookAt>
            <styleUrl>#m_ylw-pushpin</styleUrl>
            <Point>
                <gx:drawOrder>1</gx:drawOrder>
                <coordinates>8.705493968629334,49.10000674357795,0</coordinates>
            </Point>
        </Placemark>
        <Placemark>
            <name>dritte Koordinate</name>
            <LookAt>
                <longitude>8.705777196688841</longitude>
                <latitude>49.10006120849889</latitude>
                <altitude>0</altitude>
                <heading>9.306514354730476e-005</heading>
                <tilt>0</tilt>
                <range>388.7695146071881</range>
                <gx:altitudeMode>relativeToSeaFloor</gx:altitudeMode>
            </LookAt>
            <styleUrl>#m_ylw-pushpin</styleUrl>
            <Point>
                <gx:drawOrder>1</gx:drawOrder>
                <coordinates>8.705777196688839,49.10006120849888,0</coordinates>
            </Point>
        </Placemark>
    </Folder>
</Document>
</kml>
Hallo return,

wie sehen denn Deine Bemühungen bisher aus?


Gruß Carsten
Hallo DbSam,

ich hab´s jetzt schon etwas weiter.

Mein Problem ist aber noch folgendes.
Ich habe eine Abfrage geschrieben, bei welcher geprüft wird, ob die Zellen leer sind. Das funktioniert
soweit ganz gut. Blos schreibt er mir immer noch eine leere Signatur mit in die Datei.

is mächtig viel Code, da KML verschiedene Informtionen benötigt.... wobei das meiste "print"-Befehle sind Smile






Code:
Private Sub CommandButton2_Click()

   Dim intCountRow As Integer
   Dim intCountCol As Integer
   Dim strHeader As Variant
 
'Datei wird geöffnet oder angelegt, wenn sie nicht existiert.
'oder einfach überschrieben, wenn sie bereits existiert
   Open "C:\Bohrexport\Bodenprobenkoordinaten.kml" For Output As #5
 
   'Zuerst wird ein StringArray "strHeader" erzeugt, das die Spalten-
   'überschriften enthält. Dieses StringArray wird dann in am
   'Anfang jeder Zeile in die Textdatei geschrieben.
   

'Open "C:\Bohrexport\Probenzone.kml" For Output As #5

Print #5, Cells(2, 7);                                                           'hääää??
Print #5, "<?xml version=""1.0"" encoding=""UTF-8""?>"
Print #5, "<kml xmlns=""http://www.opengis.net/kml/2.2"" xmlns:gx=""http://www.google.com/kml/ext/2.2"" xmlns:kml=""http://www.opengis.net/kml/2.2"" xmlns:atom=""http://www.w3.org/2005/Atom"" > "
Print #5, "<Document>"
Print #5, "    <name>"; Cells(6, 2); "Zone "; Cells(6, 9); "Bodenproben Zone 1.kml</name>"
Print #5, "    <Style id=""sn_71"">"
Print #5, "        <IconStyle>"
Print #5, "            <scale>1.1</scale>"
Print #5, "            <Icon>"
Print #5, "                <href>http://maps.google.com/mapfiles/kml/paddle/7.png</href>"
Print #5, "            </Icon>"
Print #5, "            <hotSpot x=""32"" y=""1"" xunits=""pixels"" yunits=""pixels""/>"
Print #5, "        </IconStyle>"
Print #5, "        <ListStyle>"
Print #5, "            <ItemIcon>"
Print #5, "                <href>http://maps.google.com/mapfiles/kml/paddle/7-lv.png</href>"
Print #5, "            </ItemIcon>"
Print #5, "        </ListStyle>"
Print #5, "    </Style>"
Print #5, "    <StyleMap id=""msn_60"">"
Print #5, "        <Pair>"
Print #5, "           <key>normal</key>"
Print #5, "            <styleUrl>#sn_61</styleUrl>"
Print #5, "        </Pair>"
Print #5, "        <Pair>"
Print #5, "            <key>highlight</key>"
Print #5, "            <styleUrl>#sh_60</styleUrl>"
Print #5, "        </Pair>"
Print #5, "    </StyleMap>"
Print #5, "    <Style id=""#m_ylw-pushpin"">"
Print #5, "        <IconStyle>"
Print #5, "            <scale>1.4</scale>"
Print #5, "            <Icon>"
Print #5, "                <href>http://maps.google.com/mapfiles/kml/shapes/target.png</href>"
Print #5, "            </Icon>"
Print #5, "            <hotSpot x=""32"" y=""1"" xunits=""pixels"" yunits=""pixels""/>"
Print #5, "        </IconStyle>"
Print #5, "        <ListStyle>"
Print #5, "            <ItemIcon>"
Print #5, "                <href>http://maps.google.com/mapfiles/kml/shapes/target.png</href>"
Print #5, "            </ItemIcon>"
Print #5, "        </ListStyle>"
Print #5, "    </Style>"
Print #5, "    <Style id=""sh_31"">"
Print #5, "        <IconStyle>"
Print #5, "            <scale>1.3</scale>"
Print #5, "            <Icon>"
Print #5, "                <href>http://maps.google.com/mapfiles/kml/paddle/3.png</href>"
Print #5, "            </Icon>"
Print #5, "            <hotSpot x=""32"" y=""1"" xunits=""pixels"" yunits=""pixels""/>"
Print #5, "        </IconStyle>"
Print #5, "        <ListStyle>"
Print #5, "            <ItemIcon>"
Print #5, "                <href>http://maps.google.com/mapfiles/kml/paddle/3-lv.png</href>"
Print #5, "            </ItemIcon>"
Print #5, "        </ListStyle>"
Print #5, "    </Style>"
Print #5, "    <Style id=""sn_3"">"
Print #5, "        <IconStyle>"
Print #5, "            <scale>1.1</scale>"
Print #5, "            <Icon>"
Print #5, "                <href>http://maps.google.com/mapfiles/kml/paddle/3.png</href>"
Print #5, "            </Icon>"
Print #5, "           <hotSpot x=""32"" y=""1"" xunits=""pixels"" yunits=""pixels""/>"
Print #5, "        </IconStyle>"
Print #5, "        <ListStyle>"
Print #5, "            <ItemIcon>"
Print #5, "               <href>http://maps.google.com/mapfiles/kml/paddle/3-lv.png</href>"
Print #5, "            </ItemIcon>"
Print #5, "        </ListStyle>"
Print #5, "    </Style>"
Print #5, "    <Style id=""sn_410"">"
Print #5, "        <IconStyle>"
Print #5, "            <scale>1.1</scale>"
Print #5, "            <Icon>"
Print #5, "               <href>http://maps.google.com/mapfiles/kml/paddle/4.png</href>"
Print #5, "            </Icon>"
Print #5, "            <hotSpot x=""32"" y=""1"" xunits=""pixels"" yunits=""pixels""/>"
Print #5, "        </IconStyle>"
Print #5, "        <ListStyle>"
Print #5, "            <ItemIcon>"
Print #5, "                <href>http://maps.google.com/mapfiles/kml/paddle/4-lv.png</href>"
Print #5, "            </ItemIcon>"
Print #5, "        </ListStyle>"
Print #5, "    </Style>"
Print #5, "    <StyleMap id=""msn_420"">"
Print #5, "        <Pair>"
Print #5, "            <key>normal</key>"
Print #5, "            <styleUrl>#sn_410</styleUrl>"
Print #5, "        </Pair>"
Print #5, "        <Pair>"
Print #5, "            <key>highlight</key>"
Print #5, "            <styleUrl>#sh_41</styleUrl>"
Print #5, "        </Pair>"
Print #5, "    </StyleMap>"
Print #5, "    <StyleMap id=""msn_21"">"
Print #5, "        <Pair>"
Print #5, "            <key>normal</key>"
Print #5, "            <styleUrl>#sn_220</styleUrl>"
Print #5, "        </Pair>"
Print #5, "        <Pair>"
Print #5, "            <key>highlight</key>"
Print #5, "            <styleUrl>#sh_210</styleUrl>"
Print #5, "        </Pair>"
Print #5, "    </StyleMap>"
Print #5, "    <Style id=""sh_210"">"
Print #5, "        <IconStyle>"
Print #5, "            <scale>1.3</scale>"
Print #5, "            <Icon>"
Print #5, "                <href>http://maps.google.com/mapfiles/kml/paddle/2.png</href>"
Print #5, "            </Icon>"
Print #5, "            <hotSpot x=""32"" y=""1"" xunits=""pixels"" yunits=""pixels""/>"
Print #5, "        </IconStyle>"
Print #5, "        <ListStyle>"
Print #5, "            <ItemIcon>"
Print #5, "                <href>http://maps.google.com/mapfiles/kml/paddle/2-lv.png</href>"
Print #5, "            </ItemIcon>"
Print #5, "        </ListStyle>"
Print #5, "    </Style>"
Print #5, "    <StyleMap id=""msn_5"">"
Print #5, "        <Pair>"
Print #5, "            <key>normal</key>"
Print #5, "            <styleUrl>#sn_52</styleUrl>"
Print #5, "        </Pair>"
Print #5, "        <Pair>"
Print #5, "            <key>highlight</key>"
Print #5, "            <styleUrl>#sh_51</styleUrl>"
Print #5, "        </Pair>"
Print #5, "    </StyleMap>"
Print #5, "    <Style id=""sn_220"">"
Print #5, "        <IconStyle>"
Print #5, "            <scale>1.1</scale>"
Print #5, "            <Icon>"
Print #5, "                <href>http://maps.google.com/mapfiles/kml/paddle/2.png</href>"
Print #5, "            </Icon>"
Print #5, "            <hotSpot x=""32"" y=""1"" xunits=""pixels"" yunits=""pixels""/>"
Print #5, "        </IconStyle>"
Print #5, "        <ListStyle>"
Print #5, "            <ItemIcon>"
Print #5, "                <href>http://maps.google.com/mapfiles/kml/paddle/2-lv.png</href>"
Print #5, "            </ItemIcon>"
Print #5, "        </ListStyle>"
Print #5, "    </Style>"
Print #5, "    <Style id=""; sn_61; "">"
Print #5, "        <IconStyle>"
Print #5, "            <scale>1.1</scale>"
Print #5, "            <Icon>"
Print #5, "                <href>http://maps.google.com/mapfiles/kml/paddle/6.png</href>"
Print #5, "            </Icon>"
Print #5, "            <hotSpot x=""32"" y=""1"" xunits=""pixels"" yunits=""pixels""/>"
Print #5, "        </IconStyle>"
Print #5, "        <ListStyle>"
Print #5, "            <ItemIcon>"
Print #5, "                <href>http://maps.google.com/mapfiles/kml/paddle/6-lv.png</href>"
Print #5, "            </ItemIcon>"
Print #5, "        </ListStyle>"
Print #5, "    </Style>"
Print #5, "    <Style id=""sh_41"">"
Print #5, "        <IconStyle>"
Print #5, "            <scale>1.3</scale>"
Print #5, "            <Icon>"
Print #5, "                <href>http://maps.google.com/mapfiles/kml/paddle/4.png</href>"
Print #5, "            </Icon>"
Print #5, "            <hotSpot x=""32"" y=""1"" xunits=""pixels"" yunits=""pixels""/>"
Print #5, "        </IconStyle>"
Print #5, "        <ListStyle>"
Print #5, "            <ItemIcon>"
Print #5, "                <href>http://maps.google.com/mapfiles/kml/paddle/4-lv.png</href>"
Print #5, "            </ItemIcon>"
Print #5, "        </ListStyle>"
Print #5, "    </Style>"
Print #5, "    <StyleMap id=""m_ylw-pushpin01"">"
Print #5, "        <Pair>"
Print #5, "            <key>normal</key>"
Print #5, "            <styleUrl>#s_ylw-pushpin03</styleUrl>"
Print #5, "        </Pair>"
Print #5, "       <Pair>"
Print #5, "            <key>highlight</key>"
Print #5, "            <styleUrl>#s_ylw-pushpin_hl0</styleUrl>"
Print #5, "        </Pair>"
Print #5, "    </StyleMap>"
Print #5, "    <Style id=""s_ylw-pushpin03"">"
Print #5, "        <IconStyle>"
Print #5, "            <scale>1.1</scale>"
Print #5, "            <Icon>"
Print #5, "                <href>http://maps.google.com/mapfiles/kml/pushpin/ylw-pushpin.png</href>"
Print #5, "           </Icon>"
Print #5, "            <hotSpot x=""20"" y=""2"" xunits=""pixels"" yunits=""pixels""/>"
Print #5, "        </IconStyle>"
Print #5, "        <LineStyle>"
Print #5, "            <color>ff0000ff</color>"
Print #5, "            <width>4</width>"
Print #5, "        </LineStyle>"
Print #5, "    </Style>"
Print #5, "    <StyleMap id=""msn_30"">"
Print #5, "        <Pair>"
Print #5, "            <key>normal</key>"
Print #5, "            <styleUrl>#sn_3</styleUrl>"
Print #5, "        </Pair>"
Print #5, "        <Pair>"
Print #5, "            <key>highlight</key>"
Print #5, "            <styleUrl>#sh_31</styleUrl>"
Print #5, "        </Pair>"
Print #5, "    </StyleMap>"
Print #5, "    <StyleMap id=""m_ylw-pushpin1"">"
Print #5, "        <Pair>"
Print #5, "            <key>normal</key>"
Print #5, "            <styleUrl>#s_ylw-pushpin1</styleUrl>"
Print #5, "        </Pair>"
Print #5, "        <Pair>"
Print #5, "            <key>highlight</key>"
Print #5, "            <styleUrl>#s_ylw-pushpin_hl3</styleUrl>"
Print #5, "        </Pair>"
Print #5, "    </StyleMap>"
Print #5, "    <StyleMap id=""msn_72"">"
Print #5, "        <Pair>"
Print #5, "            <key>normal</key>"
Print #5, "            <styleUrl>#sn_71</styleUrl>"
Print #5, "        </Pair>"
Print #5, "        <Pair>"
Print #5, "            <key>highlight</key>"
Print #5, "            <styleUrl>#sh_70</styleUrl>"
Print #5, "        </Pair>"
Print #5, "    </StyleMap>"
Print #5, "    <Style id=""sh_60"">"
Print #5, "        <IconStyle>"
Print #5, "            <scale>1.3</scale>"
Print #5, "            <Icon>"
Print #5, "                <href>http://maps.google.com/mapfiles/kml/paddle/6.png</href>"
Print #5, "            </Icon>"
Print #5, "            <hotSpot x=""32"" y=""1"" xunits=""pixels"" yunits=""pixels""/>"
Print #5, "        </IconStyle>"
Print #5, "        <ListStyle>"
Print #5, "            <ItemIcon>"
Print #5, "                <href>http://maps.google.com/mapfiles/kml/paddle/6-lv.png</href>"
Print #5, "            </ItemIcon>"
Print #5, "        </ListStyle>"
Print #5, "    </Style>"
Print #5, "    <Style id=""s_ylw-pushpin_hl3"">"
Print #5, "        <IconStyle>"
Print #5, "            <scale>1.3</scale>"
Print #5, "            <Icon>"
Print #5, "                <href>http://maps.google.com/mapfiles/kml/paddle/1.png</href>"
Print #5, "            </Icon>"
Print #5, "            <hotSpot x=""32"" y=""1"" xunits=""pixels"" yunits=""pixels""/>"
Print #5, "        </IconStyle>"
Print #5, "        <ListStyle>"
Print #5, "            <ItemIcon>"
Print #5, "                <href>http://maps.google.com/mapfiles/kml/paddle/1-lv.png</href>"
Print #5, "            </ItemIcon>"
Print #5, "        </ListStyle>"
Print #5, "    </Style>"
Print #5, "    <Style id=""s_ylw-pushpin_hl0"">"
Print #5, "        <IconStyle>"
Print #5, "            <scale>1.3</scale>"
Print #5, "            <Icon>"
Print #5, "                <href>http://maps.google.com/mapfiles/kml/pushpin/ylw-pushpin.png</href>"
Print #5, "            </Icon>"
Print #5, "            <hotSpot x=""20"" y=""2"" xunits=""pixels"" yunits=""pixels""/>"
Print #5, "        </IconStyle>"
Print #5, "        <LineStyle>"
Print #5, "            <color>ff0000ff</color>"
Print #5, "            <width>4</width>"
Print #5, "        </LineStyle>"
Print #5, "    </Style>"
Print #5, "    <Style id=""sh_70"">"
Print #5, "        <IconStyle>"
Print #5, "            <scale>1.3</scale>"
Print #5, "            <Icon>"
Print #5, "                <href>http://maps.google.com/mapfiles/kml/paddle/7.png</href>"
Print #5, "            </Icon>"
Print #5, "            <hotSpot x=""32"" y=""1"" xunits=""pixels"" yunits=""pixels""/>"
Print #5, "        </IconStyle>"
Print #5, "        <ListStyle>"
Print #5, "            <ItemIcon>"
Print #5, "                <href>http://maps.google.com/mapfiles/kml/paddle/7-lv.png</href>"
Print #5, "            </ItemIcon>"
Print #5, "        </ListStyle>"
Print #5, "    </Style>"
Print #5, "    <Style id=""sh_51"">"
Print #5, "        <IconStyle>"
Print #5, "            <scale>1.3</scale>"
Print #5, "            <Icon>"
Print #5, "                <href>http://maps.google.com/mapfiles/kml/paddle/5.png</href>"
Print #5, "            </Icon>"
Print #5, "            <hotSpot x=""32"" y=""1"" xunits=""pixels"" yunits=""pixels""/>"
Print #5, "        </IconStyle>"
Print #5, "        <ListStyle>"
Print #5, "            <ItemIcon>"
Print #5, "                <href>http://maps.google.com/mapfiles/kml/paddle/5-lv.png</href>"
Print #5, "           </ItemIcon>"
Print #5, "        </ListStyle>"
Print #5, "    </Style>"
Print #5, "    <Style id=""; sn_52; "">"
Print #5, "        <IconStyle>"
Print #5, "            <scale>1.1</scale>"
Print #5, "            <Icon>"
Print #5, "                <href>http://maps.google.com/mapfiles/kml/paddle/5.png</href>"
Print #5, "            </Icon>"
Print #5, "            <hotSpot x=""; 32; "" y=""; 1; "" xunits=""; pixels; "" yunits=""; pixels; ""/>"
Print #5, "       </IconStyle>"
Print #5, "        <ListStyle>"
Print #5, "            <ItemIcon>"
Print #5, "                <href>http://maps.google.com/mapfiles/kml/paddle/5-lv.png</href>"
Print #5, "            </ItemIcon>"
Print #5, "      </ListStyle>"
Print #5, "    </Style>"
Print #5, "<Folder>"

'Variablen definition

Dim Spalte As Integer
Dim j As Integer

'Vorgabe des Startwertes

Spalte = 1
j = 10

'Schleife zum ausgeben bis leere Zelle

Do While IsEmpty(Cells(j, Spalte)) = False
    Range("NYF" & j + 100) = Range("NYD" & j + 100) - Range("NYE" & j + 100)
Spalte = Spalte + 1


'Beginn der eigentlichen Zonen


Print #5, "<name>"; Cells(6, Spalte); "Zone "; Cells(9, Spalte); "</name>"
Print #5, "<open>1</open>"
Print #5, "<Placemark>"
Print #5, "<name> Schlag: "; Cells(6, Spalte); " Zone: "; Cells(9, Spalte); " Bohrloch Nr.: "; Cells(10, Spalte); "</name>"
Print #5, "<description>Durchgeführt von FarmBlick am "; Cells(7, Spalte); "um "; Cells(8, Spalte); '
Print #5,
Print #5, "Bohrtiefe: "; Cells(13, Spalte); "cm"
Print #5,
Print #5, "Geschwindigkeit 0-5cm"; Cells(14, Spalte); "</description>"

Print #5, "      <LookAt>"
Print #5, "                <longitude>"; Cells(12, Spalte); "</longitude>"
Print #5, "                <latitude>"; Cells(11, Spalte); "</latitude>"
Print #5, "                <altitude>0</altitude>"
Print #5, "                <heading>0.0000</heading>"
Print #5, "                <tilt>0</tilt>"
Print #5, "                <range>100.0</range>"
Print #5, "                <gx:altitudeMode>relativeToSeaFloor</gx:altitudeMode>"
Print #5, "      </LookAt>"
Print #5, "<styleUrl>#m_ylw-pushpin</styleUrl>"
Print #5, "<Point>"
Print #5, "<coordinates>"; Cells(12, Spalte); ","; Cells(11, Spalte); ",0</coordinates>"
Print #5, "</Point>"
Print #5, "</Placemark>"

Loop

'Enddeklaraion für KML-Datei

Print #5, "</Folder>"
Print #5, "</Document>"
Print #5, "</kml>"





Close #5












End Sub
Hallo return,


naja, testen kann ich da nichts. Ist keine Exceldatei mit Testdaten dabei.


Konnte daher nur oberflächlich überfliegen, etwas lesbarer und nur etwas variabler gestalten. Habe ungenutzte Variablen entfernt.
Keine Ahnung, ob es Dir helfen könnte die letzte Spalte zu ermitteln, o.ä. - Habe deshalb grundsätzlich nichts geändert.

Welches Problem hast Du nun genau?
Welche leere Signatur meinst Du? Wo, an welcher Stelle?
Und was ist Dein 'Häää??'



Code:
Option Explicit

Private Sub CommandButton2_Click()
   'Den Dateiname sollte man auch irgendwo flexibel auslesen ...
   WriteKmlFile "C:\Bohrexport\Bodenprobenkoordinaten.kml", ActiveSheet
End Sub

Private Sub WriteKmlFile(ByVal FilePathAndName As String, ByVal MySheet As Worksheet)
   On Error GoTo Er
   
   Dim Spalte As Long, j As Long, lngFreeFile As Long


   lngFreeFile = FreeFile
   Open FilePathAndName For Output As lngFreeFile

   With MySheet
       Print #5, .Cells(2, 7);                                                           'hääää??
       Print #5, "<?xml version=""1.0"" encoding=""UTF-8""?>"
       Print #5, "<kml xmlns=""http://www.opengis.net/kml/2.2"" xmlns:gx=""http://www.google.com/kml/ext/2.2"" xmlns:kml=""http://www.opengis.net/kml/2.2"" xmlns:atom=""http://www.w3.org/2005/Atom"" > "
       Print #5, "<Document>"
       Print #5, "    <name>"; .Cells(6, 2); "Zone "; .Cells(6, 9); "Bodenproben Zone 1.kml</name>"
       Print #5, "    <Style id=""sn_71"">"
       Print #5, "        <IconStyle>"
       Print #5, "            <scale>1.1</scale>"
       Print #5, "            <Icon>"
       Print #5, "                <href>http://maps.google.com/mapfiles/kml/paddle/7.png</href>"
       Print #5, "            </Icon>"
       Print #5, "            <hotSpot x=""32"" y=""1"" xunits=""pixels"" yunits=""pixels""/>"
       Print #5, "        </IconStyle>"
       Print #5, "        <ListStyle>"
       Print #5, "            <ItemIcon>"
       Print #5, "                <href>http://maps.google.com/mapfiles/kml/paddle/7-lv.png</href>"
       Print #5, "            </ItemIcon>"
       Print #5, "        </ListStyle>"
       Print #5, "    </Style>"
       Print #5, "    <StyleMap id=""msn_60"">"
       Print #5, "        <Pair>"
       Print #5, "           <key>normal</key>"
       Print #5, "            <styleUrl>#sn_61</styleUrl>"
       Print #5, "        </Pair>"
       Print #5, "        <Pair>"
       Print #5, "            <key>highlight</key>"
       Print #5, "            <styleUrl>#sh_60</styleUrl>"
       Print #5, "        </Pair>"
       Print #5, "    </StyleMap>"
       Print #5, "    <Style id=""#m_ylw-pushpin"">"
       Print #5, "        <IconStyle>"
       Print #5, "            <scale>1.4</scale>"
       Print #5, "            <Icon>"
       Print #5, "                <href>http://maps.google.com/mapfiles/kml/shapes/target.png</href>"
       Print #5, "            </Icon>"
       Print #5, "            <hotSpot x=""32"" y=""1"" xunits=""pixels"" yunits=""pixels""/>"
       Print #5, "        </IconStyle>"
       Print #5, "        <ListStyle>"
       Print #5, "            <ItemIcon>"
       Print #5, "                <href>http://maps.google.com/mapfiles/kml/shapes/target.png</href>"
       Print #5, "            </ItemIcon>"
       Print #5, "        </ListStyle>"
       Print #5, "    </Style>"
       Print #5, "    <Style id=""sh_31"">"
       Print #5, "        <IconStyle>"
       Print #5, "            <scale>1.3</scale>"
       Print #5, "            <Icon>"
       Print #5, "                <href>http://maps.google.com/mapfiles/kml/paddle/3.png</href>"
       Print #5, "            </Icon>"
       Print #5, "            <hotSpot x=""32"" y=""1"" xunits=""pixels"" yunits=""pixels""/>"
       Print #5, "        </IconStyle>"
       Print #5, "        <ListStyle>"
       Print #5, "            <ItemIcon>"
       Print #5, "                <href>http://maps.google.com/mapfiles/kml/paddle/3-lv.png</href>"
       Print #5, "            </ItemIcon>"
       Print #5, "        </ListStyle>"
       Print #5, "    </Style>"
       Print #5, "    <Style id=""sn_3"">"
       Print #5, "        <IconStyle>"
       Print #5, "            <scale>1.1</scale>"
       Print #5, "            <Icon>"
       Print #5, "                <href>http://maps.google.com/mapfiles/kml/paddle/3.png</href>"
       Print #5, "            </Icon>"
       Print #5, "           <hotSpot x=""32"" y=""1"" xunits=""pixels"" yunits=""pixels""/>"
       Print #5, "        </IconStyle>"
       Print #5, "        <ListStyle>"
       Print #5, "            <ItemIcon>"
       Print #5, "               <href>http://maps.google.com/mapfiles/kml/paddle/3-lv.png</href>"
       Print #5, "            </ItemIcon>"
       Print #5, "        </ListStyle>"
       Print #5, "    </Style>"
       Print #5, "    <Style id=""sn_410"">"
       Print #5, "        <IconStyle>"
       Print #5, "            <scale>1.1</scale>"
       Print #5, "            <Icon>"
       Print #5, "               <href>http://maps.google.com/mapfiles/kml/paddle/4.png</href>"
       Print #5, "            </Icon>"
       Print #5, "            <hotSpot x=""32"" y=""1"" xunits=""pixels"" yunits=""pixels""/>"
       Print #5, "        </IconStyle>"
       Print #5, "        <ListStyle>"
       Print #5, "            <ItemIcon>"
       Print #5, "                <href>http://maps.google.com/mapfiles/kml/paddle/4-lv.png</href>"
       Print #5, "            </ItemIcon>"
       Print #5, "        </ListStyle>"
       Print #5, "    </Style>"
       Print #5, "    <StyleMap id=""msn_420"">"
       Print #5, "        <Pair>"
       Print #5, "            <key>normal</key>"
       Print #5, "            <styleUrl>#sn_410</styleUrl>"
       Print #5, "        </Pair>"
       Print #5, "        <Pair>"
       Print #5, "            <key>highlight</key>"
       Print #5, "            <styleUrl>#sh_41</styleUrl>"
       Print #5, "        </Pair>"
       Print #5, "    </StyleMap>"
       Print #5, "    <StyleMap id=""msn_21"">"
       Print #5, "        <Pair>"
       Print #5, "            <key>normal</key>"
       Print #5, "            <styleUrl>#sn_220</styleUrl>"
       Print #5, "        </Pair>"
       Print #5, "        <Pair>"
       Print #5, "            <key>highlight</key>"
       Print #5, "            <styleUrl>#sh_210</styleUrl>"
       Print #5, "        </Pair>"
       Print #5, "    </StyleMap>"
       Print #5, "    <Style id=""sh_210"">"
       Print #5, "        <IconStyle>"
       Print #5, "            <scale>1.3</scale>"
       Print #5, "            <Icon>"
       Print #5, "                <href>http://maps.google.com/mapfiles/kml/paddle/2.png</href>"
       Print #5, "            </Icon>"
       Print #5, "            <hotSpot x=""32"" y=""1"" xunits=""pixels"" yunits=""pixels""/>"
       Print #5, "        </IconStyle>"
       Print #5, "        <ListStyle>"
       Print #5, "            <ItemIcon>"
       Print #5, "                <href>http://maps.google.com/mapfiles/kml/paddle/2-lv.png</href>"
       Print #5, "            </ItemIcon>"
       Print #5, "        </ListStyle>"
       Print #5, "    </Style>"
       Print #5, "    <StyleMap id=""msn_5"">"
       Print #5, "        <Pair>"
       Print #5, "            <key>normal</key>"
       Print #5, "            <styleUrl>#sn_52</styleUrl>"
       Print #5, "        </Pair>"
       Print #5, "        <Pair>"
       Print #5, "            <key>highlight</key>"
       Print #5, "            <styleUrl>#sh_51</styleUrl>"
       Print #5, "        </Pair>"
       Print #5, "    </StyleMap>"
       Print #5, "    <Style id=""sn_220"">"
       Print #5, "        <IconStyle>"
       Print #5, "            <scale>1.1</scale>"
       Print #5, "            <Icon>"
       Print #5, "                <href>http://maps.google.com/mapfiles/kml/paddle/2.png</href>"
       Print #5, "            </Icon>"
       Print #5, "            <hotSpot x=""32"" y=""1"" xunits=""pixels"" yunits=""pixels""/>"
       Print #5, "        </IconStyle>"
       Print #5, "        <ListStyle>"
       Print #5, "            <ItemIcon>"
       Print #5, "                <href>http://maps.google.com/mapfiles/kml/paddle/2-lv.png</href>"
       Print #5, "            </ItemIcon>"
       Print #5, "        </ListStyle>"
       Print #5, "    </Style>"
       Print #5, "    <Style id=""; sn_61; "">"
       Print #5, "        <IconStyle>"
       Print #5, "            <scale>1.1</scale>"
       Print #5, "            <Icon>"
       Print #5, "                <href>http://maps.google.com/mapfiles/kml/paddle/6.png</href>"
       Print #5, "            </Icon>"
       Print #5, "            <hotSpot x=""32"" y=""1"" xunits=""pixels"" yunits=""pixels""/>"
       Print #5, "        </IconStyle>"
       Print #5, "        <ListStyle>"
       Print #5, "            <ItemIcon>"
       Print #5, "                <href>http://maps.google.com/mapfiles/kml/paddle/6-lv.png</href>"
       Print #5, "            </ItemIcon>"
       Print #5, "        </ListStyle>"
       Print #5, "    </Style>"
       Print #5, "    <Style id=""sh_41"">"
       Print #5, "        <IconStyle>"
       Print #5, "            <scale>1.3</scale>"
       Print #5, "            <Icon>"
       Print #5, "                <href>http://maps.google.com/mapfiles/kml/paddle/4.png</href>"
       Print #5, "            </Icon>"
       Print #5, "            <hotSpot x=""32"" y=""1"" xunits=""pixels"" yunits=""pixels""/>"
       Print #5, "        </IconStyle>"
       Print #5, "        <ListStyle>"
       Print #5, "            <ItemIcon>"
       Print #5, "                <href>http://maps.google.com/mapfiles/kml/paddle/4-lv.png</href>"
       Print #5, "            </ItemIcon>"
       Print #5, "        </ListStyle>"
       Print #5, "    </Style>"
       Print #5, "    <StyleMap id=""m_ylw-pushpin01"">"
       Print #5, "        <Pair>"
       Print #5, "            <key>normal</key>"
       Print #5, "            <styleUrl>#s_ylw-pushpin03</styleUrl>"
       Print #5, "        </Pair>"
       Print #5, "       <Pair>"
       Print #5, "            <key>highlight</key>"
       Print #5, "            <styleUrl>#s_ylw-pushpin_hl0</styleUrl>"
       Print #5, "        </Pair>"
       Print #5, "    </StyleMap>"
       Print #5, "    <Style id=""s_ylw-pushpin03"">"
       Print #5, "        <IconStyle>"
       Print #5, "            <scale>1.1</scale>"
       Print #5, "            <Icon>"
       Print #5, "                <href>http://maps.google.com/mapfiles/kml/pushpin/ylw-pushpin.png</href>"
       Print #5, "           </Icon>"
       Print #5, "            <hotSpot x=""20"" y=""2"" xunits=""pixels"" yunits=""pixels""/>"
       Print #5, "        </IconStyle>"
       Print #5, "        <LineStyle>"
       Print #5, "            <color>ff0000ff</color>"
       Print #5, "            <width>4</width>"
       Print #5, "        </LineStyle>"
       Print #5, "    </Style>"
       Print #5, "    <StyleMap id=""msn_30"">"
       Print #5, "        <Pair>"
       Print #5, "            <key>normal</key>"
       Print #5, "            <styleUrl>#sn_3</styleUrl>"
       Print #5, "        </Pair>"
       Print #5, "        <Pair>"
       Print #5, "            <key>highlight</key>"
       Print #5, "            <styleUrl>#sh_31</styleUrl>"
       Print #5, "        </Pair>"
       Print #5, "    </StyleMap>"
       Print #5, "    <StyleMap id=""m_ylw-pushpin1"">"
       Print #5, "        <Pair>"
       Print #5, "            <key>normal</key>"
       Print #5, "            <styleUrl>#s_ylw-pushpin1</styleUrl>"
       Print #5, "        </Pair>"
       Print #5, "        <Pair>"
       Print #5, "            <key>highlight</key>"
       Print #5, "            <styleUrl>#s_ylw-pushpin_hl3</styleUrl>"
       Print #5, "        </Pair>"
       Print #5, "    </StyleMap>"
       Print #5, "    <StyleMap id=""msn_72"">"
       Print #5, "        <Pair>"
       Print #5, "            <key>normal</key>"
       Print #5, "            <styleUrl>#sn_71</styleUrl>"
       Print #5, "        </Pair>"
       Print #5, "        <Pair>"
       Print #5, "            <key>highlight</key>"
       Print #5, "            <styleUrl>#sh_70</styleUrl>"
       Print #5, "        </Pair>"
       Print #5, "    </StyleMap>"
       Print #5, "    <Style id=""sh_60"">"
       Print #5, "        <IconStyle>"
       Print #5, "            <scale>1.3</scale>"
       Print #5, "            <Icon>"
       Print #5, "                <href>http://maps.google.com/mapfiles/kml/paddle/6.png</href>"
       Print #5, "            </Icon>"
       Print #5, "            <hotSpot x=""32"" y=""1"" xunits=""pixels"" yunits=""pixels""/>"
       Print #5, "        </IconStyle>"
       Print #5, "        <ListStyle>"
       Print #5, "            <ItemIcon>"
       Print #5, "                <href>http://maps.google.com/mapfiles/kml/paddle/6-lv.png</href>"
       Print #5, "            </ItemIcon>"
       Print #5, "        </ListStyle>"
       Print #5, "    </Style>"
       Print #5, "    <Style id=""s_ylw-pushpin_hl3"">"
       Print #5, "        <IconStyle>"
       Print #5, "            <scale>1.3</scale>"
       Print #5, "            <Icon>"
       Print #5, "                <href>http://maps.google.com/mapfiles/kml/paddle/1.png</href>"
       Print #5, "            </Icon>"
       Print #5, "            <hotSpot x=""32"" y=""1"" xunits=""pixels"" yunits=""pixels""/>"
       Print #5, "        </IconStyle>"
       Print #5, "        <ListStyle>"
       Print #5, "            <ItemIcon>"
       Print #5, "                <href>http://maps.google.com/mapfiles/kml/paddle/1-lv.png</href>"
       Print #5, "            </ItemIcon>"
       Print #5, "        </ListStyle>"
       Print #5, "    </Style>"
       Print #5, "    <Style id=""s_ylw-pushpin_hl0"">"
       Print #5, "        <IconStyle>"
       Print #5, "            <scale>1.3</scale>"
       Print #5, "            <Icon>"
       Print #5, "                <href>http://maps.google.com/mapfiles/kml/pushpin/ylw-pushpin.png</href>"
       Print #5, "            </Icon>"
       Print #5, "            <hotSpot x=""20"" y=""2"" xunits=""pixels"" yunits=""pixels""/>"
       Print #5, "        </IconStyle>"
       Print #5, "        <LineStyle>"
       Print #5, "            <color>ff0000ff</color>"
       Print #5, "            <width>4</width>"
       Print #5, "        </LineStyle>"
       Print #5, "    </Style>"
       Print #5, "    <Style id=""sh_70"">"
       Print #5, "        <IconStyle>"
       Print #5, "            <scale>1.3</scale>"
       Print #5, "            <Icon>"
       Print #5, "                <href>http://maps.google.com/mapfiles/kml/paddle/7.png</href>"
       Print #5, "            </Icon>"
       Print #5, "            <hotSpot x=""32"" y=""1"" xunits=""pixels"" yunits=""pixels""/>"
       Print #5, "        </IconStyle>"
       Print #5, "        <ListStyle>"
       Print #5, "            <ItemIcon>"
       Print #5, "                <href>http://maps.google.com/mapfiles/kml/paddle/7-lv.png</href>"
       Print #5, "            </ItemIcon>"
       Print #5, "        </ListStyle>"
       Print #5, "    </Style>"
       Print #5, "    <Style id=""sh_51"">"
       Print #5, "        <IconStyle>"
       Print #5, "            <scale>1.3</scale>"
       Print #5, "            <Icon>"
       Print #5, "                <href>http://maps.google.com/mapfiles/kml/paddle/5.png</href>"
       Print #5, "            </Icon>"
       Print #5, "            <hotSpot x=""32"" y=""1"" xunits=""pixels"" yunits=""pixels""/>"
       Print #5, "        </IconStyle>"
       Print #5, "        <ListStyle>"
       Print #5, "            <ItemIcon>"
       Print #5, "                <href>http://maps.google.com/mapfiles/kml/paddle/5-lv.png</href>"
       Print #5, "           </ItemIcon>"
       Print #5, "        </ListStyle>"
       Print #5, "    </Style>"
       Print #5, "    <Style id=""; sn_52; "">"
       Print #5, "        <IconStyle>"
       Print #5, "            <scale>1.1</scale>"
       Print #5, "            <Icon>"
       Print #5, "                <href>http://maps.google.com/mapfiles/kml/paddle/5.png</href>"
       Print #5, "            </Icon>"
       Print #5, "            <hotSpot x=""; 32; "" y=""; 1; "" xunits=""; pixels; "" yunits=""; pixels; ""/>"
       Print #5, "       </IconStyle>"
       Print #5, "        <ListStyle>"
       Print #5, "            <ItemIcon>"
       Print #5, "                <href>http://maps.google.com/mapfiles/kml/paddle/5-lv.png</href>"
       Print #5, "            </ItemIcon>"
       Print #5, "      </ListStyle>"
       Print #5, "    </Style>"
       Print #5, "<Folder>"
       
       'Vorgabe des Startwertes:
       Spalte = 1
       j = 10
   
       'Schleife zum ausgeben bis leere Zelle:
       Do While IsEmpty(.Cells(j, Spalte)) = False
           .Range("NYF" & j + 100) = .Range("NYD" & j + 100) - .Range("NYE" & j + 100)
           Spalte = Spalte + 1
       
           'Beginn der eigentlichen Zonen
           Print #5, "<name>"; .Cells(6, Spalte); "Zone "; .Cells(9, Spalte); "</name>"
           Print #5, "<open>1</open>"
           Print #5, "<Placemark>"
           Print #5, "<name> Schlag: "; .Cells(6, Spalte); " Zone: "; .Cells(9, Spalte); " Bohrloch Nr.: "; .Cells(10, Spalte); "</name>"
           Print #5, "<description>Durchgeführt von FarmBlick am "; .Cells(7, Spalte); "um "; .Cells(8, Spalte); '
           Print #5,
           Print #5, "Bohrtiefe: "; .Cells(13, Spalte); "cm"
           Print #5,
           Print #5, "Geschwindigkeit 0-5cm"; .Cells(14, Spalte); "</description>"
           
           Print #5, "      <LookAt>"
           Print #5, "                <longitude>"; .Cells(12, Spalte); "</longitude>"
           Print #5, "                <latitude>"; .Cells(11, Spalte); "</latitude>"
           Print #5, "                <altitude>0</altitude>"
           Print #5, "                <heading>0.0000</heading>"
           Print #5, "                <tilt>0</tilt>"
           Print #5, "                <range>100.0</range>"
           Print #5, "                <gx:altitudeMode>relativeToSeaFloor</gx:altitudeMode>"
           Print #5, "      </LookAt>"
           Print #5, "<styleUrl>#m_ylw-pushpin</styleUrl>"
           Print #5, "<Point>"
           Print #5, "<coordinates>"; .Cells(12, Spalte); ","; .Cells(11, Spalte); ",0</coordinates>"
           Print #5, "</Point>"
           Print #5, "</Placemark>"
       
       Loop
   End With
   
   'Enddeklaraion für KML-Datei
   Print #5, "</Folder>"
   Print #5, "</Document>"
   Print #5, "</kml>"

   Close lngFreeFile

Ex:
   On Error Resume Next
   Close lngFreeFile
Er:
   MsgBox Err.Number & vbNewLine & Err.Description, vbCritical, "Fehler in der Sub Irgendwas"
   Resume Ex
   'for debug:
   Resume Next
End Sub


Gruß Carsten
Hi,

das häääää ist eine Floskel von mir. Ich wusste nicht warum ich das da rein gemacht habe. Ist mittlerweile weg
:05: 

Wenn ich die Daten exportiere (siehe beigefügtes Excel) und es anschließend in GoogleEarth importiere, macht er mir
eine neue "Zone" (findest Du im Code). Ich habe da so die Vermutung, dass mit meiner loop etwas nicht stimmt. Er sollte
eigentlich aufhören, wenn es keine volle Spalte mehr gibt.

Viele Grüße

Oliver
Code:
Sub M_snb()
   sn = Sheet1.Cells(1).CurrentRegion
   sp = Sheet1.Cells(11, 1).CurrentRegion
   
   c00 = Replace(sp(1, 1), "~", sn(4, 1))
   For j = 1 To UBound(sn, 2)
       c00 = c00 & vbLf & Replace(Replace(Replace(sp(1, 2), "~4", sn(4, j)), "~5", sn(5, j)), "~6", sn(6, j))
   Next
   c00 = c00 & vbLf & sp(1, 3)
   
   CreateObject("scripting.filesystemobject").createtextfile("G:\OF\GPS_001.xml").write c00
End Sub
Hallo snb,

ich sag mal Danke..... aber so richtig fällt bei mir der Groschen nicht, was Du mir damit sagen willst....

Bin ein absoluter noob in VBA :s 

Viele Grüße

Oliver
Hallo Oliver,

bitte teste mal:
[attachment=11080]

Dein Fehler lag im Loop.
Du hast die Zelle abgefragt und gleich danach die Spalte hochgezählt. Und die war leer.



Gruß Carsten
Danke,

ich schaus mir gleich an

Viele Grüße

Oliver
Hi Carsten,

vielen herzlichen Dank. Ich war so stolz, dass ich mit meinem nicht vorhandenen Wissen das hinbekommen habe..... Aber jetzt..... viel
übersichtlicher und vor allem...... es funktioniert.

Ich trau mich ja garnicht zu fragen..... aber ich hätte da noch ein zwei Probleme.... könntest Du mir da auch helfen?

Und zwar würde ich gerne den Export-Ordner für die KML sowie den Import-Ordner für die Textdatei auswählen können.

Das andere, sitze da schon seit 12:00 Uhr heute dran, ist etwas komplizierter. Und zwar kann sich der Kunde ädern (in der Tabelle). Mein
Ziel wäre, dass dies automatisch erkannt wird und dann eine neue KML-Datei mit dem jeweiligen Kundennamen geschrieben wird.
Das Probelm ist (für mich) wie ich das mit den ganzen Headern in der KML-Struktur hinbekommen soll, bzw. wie ich das am besten erkenne?
Ich hab mal was mit Do While versucht, aber nicht zum laufen bekommen.

Ich sag mal pauschal 1000 Dank hast mir sehr, sehr geholfen, auch wenn das andere für Dich nicht in Frage kommt.

Liebe Grüße

Oliver
Seiten: 1 2 3