宏用于创建包含单元格和文本值的文本文件


0

我试图在Excel中创建一个宏来创建一个文本文件,其中一些参数在excel单元格上。

输出将是例如:

这个孩子是'细胞(1,1)'老。

他的名字是'cell(1,2)'

我已经设法创建文件,但我在文本中间添加变量。请关注我写的代码:

Sub Generate_KML()

Dim strPath                            As String
Dim iFileNumber                        As Long
Dim strHeader                          As String
Dim strData                            As String

strPath = Application.GetSaveAsFilename(FileFilter:= _
"KML File (*.kml), *.kml", Title:="Save Location")

iFileNumber = FreeFile()
strHeader = ActiveCell.Offset(1, 1)
strData = "Test 2"

Open strPath For Output As #iFileNumber
Print #iFileNumber, strHeader
Print #iFileNumber, strData

Close #iFileNumber
End Sub 

谢谢!此致,理查德利马

Answers:


0

你是什​​么意思在挣扎?

strdata = "The kid is " & cells(1,1).value & "His name is " cells(1,2).value

你几乎把它弄下来,只是&用来连接。

如果您正在努力阅读打印件,请参阅此问题以获取示例。

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.