0

我正在使用此代码制作 KML 文件:

Sub Create_KML()
' Builds KML from spread sheet
' Keyboard Shortcut: Ctrl+c
'
'Trash = Application _
'    .GetOpenFilename("Text Files (*.txt), *.txt")
'Open File For Random As #1 ' "c:\Users\mwilson\Desktop\Trash.txt
'Open "c:\Users\mwilson\Desktop\Test Google\Trash.txt" For Output As #1
Open "C:\Documents and Settings\eecoop\Desktop\10 day avg rssi Google kml\Trash.kml" For Output As #1
y = 9
Address = Range("B" & y) ' "203 Jordan, Tallassee, AL"
While Address <> ""
'**************
Print #1, "<?xml version=""1.0"" encoding=""utf-8""?>"         '1
Print #1, "<kml xmlns=""http://www.opengis.net/kml/2.2"">"     '2
Print #1, "   <Placemark>"                                        '3
Print #1, "     <name>George</name>"                           '4
Print #1, "        <Style>"                                     '5
Print #1, "           <IconStyle>"                              '6
Print #1, "               <scale>.3</scale>"                    '7
Print #1, "               <Icon>"                               '8
Print #1, "                  <href>Green.png</href>"             '9
Print #1, "               </Icon>"                             '10
Print #1, "            </IconStyle>"                            '11
Print #1, "        </Style>"                                     '12
Print #1, "     <address>" & Address & "</address>"    '13
Print #1, " </Placemark>"                                        '14
Print #1, "</kml>"                                               '15
Print #1, " "
'********
'    Range("A2").Select
        ID = ActiveCell.FormulaR1C1
'    Range("B2").Select
        Address = ActiveCell.FormulaR1C1
'    Range("C2").Select
'        RSSI = ActiveCell.FormulaR1C1
'    Trash.Write ("hi")

'    Print #1, ID
y = y + 1
Address = Range("B" & y)
Wend
    Close #1
End Sub

在大多数情况下,它工作得很好,除了当我尝试设置Address等于Range("B" & Y)which 有字符串时:

203约旦,塔拉西,阿拉巴马州

当我这样做时,它会从谷歌地球的屏幕上打印出来,而如果我直接使用引用的地址,即:Address = "203 Jordan, Tallassee, AL"

它工作得很好,并绘制了它应该在哪里以及如何做。我试图确保Address从 Excel 单元格中提取时格式化为文本,但错误不断发生。

我究竟做错了什么?

4

3 回答 3

0

尝试使用文本编辑器打开 KML,看看<address>在您的 2 种情况下该行的格式是否不同。

于 2009-05-27T23:47:32.073 回答
0

我会尝试使用

Address("B" & y).Value
cstr(Address("B" & y))
于 2009-05-27T23:50:04.003 回答
0

我想到了。输入的两个项目存在差异。

在我从老板那里得到的 Excel 文件中,他拼错了 Talassee。他只用了一个s。我也不得不改变:

> & Address & <

到:

>; Address; "<

现在它工作正常。此外,当您一次绘制大量点时,Google 地球尚未处理的点将显示为好像它们不在屏幕上一样。

于 2009-05-28T13:06:03.947 回答