Ark68
Well-known Member
- Joined
- Mar 23, 2004
- Messages
- 4,616
- Office Version
- 365
- 2016
- Platform
- Windows
Sorry for the vague title ... I am kinda at a loss of words on how to best describe what I am looking to do.
I am using Excel VBA to extract, analyse and format worksheet data to create a KML file. I have thousands of rows of data to be compiled into the final KML project.
The data is one worksheet, and the KML is built line by line in the destination worksheet.
The task is to put each new KML code on the row immediately below the previous.
It seems simple, but I am looking for efficient code to advancethe target row by one with each new line of KML.
The way I have been doing it is as simple as this ... (sample)
And so on. Each new line is referenced by a cell range value. Of course this works, but if I need to add a line anywhere tjrough the code, I have to change ALL the numbers in the cell reference manually. An annoying task when dealing with hundreds of lines of code.
Then I tried ... (sample)
This to works, and resolves the need to have to manually change row references in cell ranges as was necessary in the first example. But with this method, I'm doubling the amount of lines of code, which not only makes for tedious coding, but may impact the performance of the script.
Can anyone suggest a more efficient method of doing what I need to accomplish?
I did try this, but the result is an "Automation error". Clearly this is not a doable method, but was worth the try I suppose.
I am using Excel VBA to extract, analyse and format worksheet data to create a KML file. I have thousands of rows of data to be compiled into the final KML project.
The data is one worksheet, and the KML is built line by line in the destination worksheet.
The task is to put each new KML code on the row immediately below the previous.
It seems simple, but I am looking for efficient code to advancethe target row by one with each new line of KML.
The way I have been doing it is as simple as this ... (sample)
Code:
With ws_destination
.range("A1") = "/?xml version=" & Chr(34) & "1.0" & Chr(34) & " encoding=" & Chr(34) & "UTF-8" & Chr(34) & "?>"
.range("A2") = "/kml xmlns=" & Chr(34) & "http://www.opengis.net/kml/2.2" & Chr(34) & " xmlns:gx=" & Chr(34) & "http://www.google.com/kml/ext/2.2" & Chr(34) & " xmlns:kml=" & Chr(34) & "http://www.opengis.net/kml/2.2" & Chr(34) & " xmlns:atom=" & Chr(34) & "http://www.w3.org/2005/Atom" & Chr(34) & ">"
.range("A3") = " /Document>"
...
End With
And so on. Each new line is referenced by a cell range value. Of course this works, but if I need to add a line anywhere tjrough the code, I have to change ALL the numbers in the cell reference manually. An annoying task when dealing with hundreds of lines of code.
Then I tried ... (sample)
Code:
x=1
With ws_destination
.range("A" & x) = "/?xml version=" & Chr(34) & "1.0" & Chr(34) & " encoding=" & Chr(34) & "UTF-8" & Chr(34) & "?>"
x = x + 1
.range("A" & x) = "/kml xmlns=" & Chr(34) & "http://www.opengis.net/kml/2.2" & Chr(34) & " xmlns:gx=" & Chr(34) & "http://www.google.com/kml/ext/2.2" & Chr(34) & " xmlns:kml=" & Chr(34) & "http://www.opengis.net/kml/2.2" & Chr(34) & " xmlns:atom=" & Chr(34) & "http://www.w3.org/2005/Atom" & Chr(34) & ">"
x = x + 1
.range("A" & x) = " /Document>"
x = x + 1
...
End With
This to works, and resolves the need to have to manually change row references in cell ranges as was necessary in the first example. But with this method, I'm doubling the amount of lines of code, which not only makes for tedious coding, but may impact the performance of the script.
Can anyone suggest a more efficient method of doing what I need to accomplish?
I did try this, but the result is an "Automation error". Clearly this is not a doable method, but was worth the try I suppose.
Code:
With ws_dest
ActiveWindow.DisplayGridlines = False
.Columns("A").ColumnWidth = 255
x = 0
.Range("A" & x + 1) = "/?xml version=" & Chr(34) & "1.0" & Chr(34) & " encoding=" & Chr(34) & "UTF-8" & Chr(34) & "?/"
.Range("A" & x + 1) = "/kml xmlns=" & Chr(34) & "http://www.opengis.net/kml/2.2" & Chr(34) & " xmlns:gx=" & Chr(34) & "http://www.google.com/kml/ext/2.2" & Chr(34) & " xmlns:kml=" & Chr(34) & "http://www.opengis.net/kml/2.2" & Chr(34) & " xmlns:atom=" & Chr(34) & "http://www.w3.org/2005/Atom" & Chr(34) & "/"
.Range("A" & x + 1) = " /Document/"
....
End With
Last edited: