This is an example of creating a new text file from an old, inserting a new
second line.
Then the macro deletes the original file and renames the new one to the old.
An xml file is like a text file.
Very much like a text file<g
--
Jim
Sub a()
Dim TextLine As String
Open "c:\file.txt" For Input As #1
Open "c:\newfile.txt" For Output As #2
Line Input #1, TextLine
Print #2, TextLine
Print #2, "Inserted text"
Do While Not EOF(1)
Line Input #1, TextLine
Print #2, TextLine
Loop
Close #1
Close #2
Kill "c:\file.txt"
Name "c:\newfile.txt" As "c:\file.txt"
End Sub
"scantor145" wrote
in message ...
|
| No, sorry. Maybe I wasn't clear enough. The xml file as listed is NOT
| in an Excel spreadsheet. An xml file is like a text file. I want to
| WRITE some text to a specific location within the xml file via macro
| commands, save it then open it up in Excel.
|
| Sorry for any confusion. :(
|
|
|
|
|
|
|
| Jim Rech Wrote:
| So you just want to insert a row and put some text in A2?
|
| If so then:
|
| Rows(2).Insert
| Range("A2").Value = "<?xml-stylesheet type=""text/xsl""
| href=""2simplesamples.xsl""?"
|
|
| --
| Jim
| "scantor145"
| wrote
| in message
| ...
| |
| | Excel 2002 with Visual Basic 6.3
| |
| | I have an XML file, which I'll call 2SimpleSamples.xml
| |
| | <?xml version="1.0"?
| | <NewDataSet
| | <Measurements
| | <Index0</Index
| | <Pos1</Pos
| | <ChemNumber7</ChemNumber
| | <ReadNumber1</ReadNumber
| | <Repeats0</Repeats
| | <FilterNumber1</FilterNumber
| | <Signal193075</Signal
| | <Reference76668</Reference
| | <TimeStamp1255</TimeStamp
| | </Measurements
| | <Measurements
| | <Index1</Index
| | <Pos1</Pos
| | <ChemNumber7</ChemNumber
| | <ReadNumber2</ReadNumber
| | <Repeats0</Repeats
| | <FilterNumber1</FilterNumber
| | <Signal191867</Signal
| | <Reference76204</Reference
| | <TimeStamp1496</TimeStamp
| | </Measurements
| | </NewDataSet
| |
| | In a macro I have commands to select the xml file:
| |
| |
| |
| | Code:
| | --------------------
| | FilterList = "XML Files(*.xml),*.xml" 'Type of file to open
| |
| |
| | With Application
| | MyFileMod = .GetOpenFilename(filefilter:=FilterList)
| | End With
| | --------------------
| |
| | In order to format the data in a prescribed way in Excel, I have
| | another file called 2SimpleSamples.xsl which is a style sheet
| | associated with the file 2Simplesamples.xml. Actually, inserting the
| | following line between <?xml version="1.0"? and <NewDataSet in the
| | xml file above makes the association:
| |
| | <?xml-stylesheet type="text/xsl" href="2simplesamples.xsl"?
| |
| | In my macro, after I open the xml file I need to insert(write) the
| | above line into the xml file. Is it possible, and if so, how?
| |
| | Thanks
| |
| |
| | --
| | scantor145
| |
| ------------------------------------------------------------------------
| | scantor145's Profile:
|
http://www.excelforum.com/member.php...o&userid=14766
| | View this thread:
|
http://www.excelforum.com/showthread...hreadid=383308
| |
|
|
| --
| scantor145
| ------------------------------------------------------------------------
| scantor145's Profile:
http://www.excelforum.com/member.php...o&userid=14766
| View this thread:
http://www.excelforum.com/showthread...hreadid=383308
|