0

Im trying to create a macro in excel that creates a text file which some of the parameters are on excel cells.

The output would be for example:

The kid is 'cell (1,1)' old.

His name is 'cell (1,2)'.

I managed already to create the file but Im straggling to add the variable in the middle of the text. Follow bellow the code that I have written:

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 

Thank you! Regards, Richard Lima

1 Answer 1

0

What do you mean you're struggling?

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

You pretty much have it down, just use & to concatenate.

If you're struggling with the print, see this question for examples.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .