Oops.Just realized that you need to specify the path for the output file!You 
could specify the folder in some way, or take the path from the input file.to 
do that, try this:
Option Explicit
Public Const ForReading = 1, ForWriting = 2, ForAppending = 8
Sub Replace_in_XML()
    Dim fIN, fOut, fso, I, XMLName, NewXML
    Dim RowNum, NumRows, Str
    Dim StrFrom, StrTo, f, fPath    XMLName = 
ThisWorkbook.Sheets(1).Range("F7").Value
    
    
    NumRows = ActiveCell.SpecialCells(xlLastCell).Row
    
    Set fso = CreateObject("Scripting.FileSystemObject")
    
    If (Not fso.fileexists(XMLName)) Then
        MsgBox "File Not found" & Chr(13) & XMLName
        Exit Sub
    Else
        Set f = fso.getfile(XMLName)
        fPath = f.Parentfolder
        If (Right(fPath, 1) <> "\") Then fPath = fPath & "\"
    End If
    NewXML = fPath & "HGSJAM-Encompass_" & Format(Now(), "MMDDYY-HH:MM AM/PM") 
& "_1.xml"""
    If (fso.fileexists(NewXML)) Then
        fso.deletefile NewXML
    End If
    
    Set fIN = fso.OpenTextFile(XMLName, ForReading)
'    Set fOut = fso.OpenTextFile(NewXML, ForWriting)
'    fOut.Close
    Set fOut = fso.OpenTextFile(NewXML, ForAppending, True)
    
'------------------------------------------------------------------------------------
    While Not fIN.atendofstream
        Str = fIN.readline
        For RowNum = 1 To NumRows
            If ((ThisWorkbook.Sheets(1).Cells(RowNum, "A").Value & "X" <> "X") _
            And (ThisWorkbook.Sheets(1).Cells(RowNum, "B").Value & "X" <> "X")) 
Then
                Str = Replace(Str, Cells(RowNum, "A").Value, Cells(RowNum, 
"B").Value)
            End If
        Next RowNum
        fOut.writeline Str
    Wend
    
'------------------------------------------------------------------------------------
    fIN.Close
    fOut.Close
    MsgBox "finished"
End Sub
 Paul-----------------------------------------
“Do all the good you can,
By all the means you can,
In all the ways you can,
In all the places you can,
At all the times you can,
To all the people you can,
As long as ever you can.” - John Wesley
----------------------------------------- 

    On Friday, April 1, 2016 12:06 PM, Secret Shot <secrets...@gmail.com> wrote:
 
 

 Dear Paul,
thanks Sir, You made my day. . you are really a true and always help in this 
group. 
I just want one more thing, which will greatfully.
after making changes can the new file be saved in this name formate
"HGSJAM-Encompass_MMDDYY-HH:MM AM/PM_1.xml"
Please if I can get this help it would be a big relief for me. 
On Fri, Apr 1, 2016 at 6:40 PM, Paul Schreiner <schreiner_p...@att.net> wrote:

Try a macro like this:
Option Explicit
Public Const ForReading = 1, ForWriting = 2, ForAppending = 8
Sub Replace_in_XML()
    Dim fIN, fOut, fso, I, XMLName, NewXML
    Dim RowNum, NumRows, Str
    Dim StrFrom, StrTo    XMLName = ThisWorkbook.Sheets(1).Range("F7").Value
    NewXML = Replace(XMLName, ".xml", "_New.xml")
    
    NumRows = ActiveCell.SpecialCells(xlLastCell).Row
    
    Set fso = CreateObject("Scripting.FileSystemObject")
    
    If (Not fso.fileexists(XMLName)) Then
        MsgBox "File Not found" & Chr(13) & XMLName
        Exit Sub
    End If
    If (fso.fileexists(NewXML)) Then
        fso.deletefile NewXML
    End If
    
    Set fIN = fso.OpenTextFile(XMLName, ForReading)
'    Set fOut = fso.OpenTextFile(NewXML, ForWriting)
'    fOut.Close
    Set fOut = fso.OpenTextFile(NewXML, ForAppending, True)
    
'------------------------------------------------------------------------------------
    While Not fIN.atendofstream
        Str = fIN.readline
        For RowNum = 1 To NumRows
            If ((ThisWorkbook.Sheets(1).Cells(RowNum, "A").Value & "X" <> "X") _
            And (ThisWorkbook.Sheets(1).Cells(RowNum, "B").Value & "X" <> "X")) 
Then
                Str = Replace(Str, Cells(RowNum, "A").Value, Cells(RowNum, 
"B").Value)
            End If
        Next RowNum
        fOut.writeline Str
    Wend
    
'------------------------------------------------------------------------------------
    fIN.Close
    fOut.Close
    MsgBox "finished"
End Sub Paul-----------------------------------------
“Do all the good you can,
By all the means you can,
In all the ways you can,
In all the places you can,
At all the times you can,
To all the people you can,
As long as ever you can.” - John Wesley
----------------------------------------- 

    On Friday, April 1, 2016 8:28 AM, Secret Shot <secrets...@gmail.com> wrote:
 
 

 Dear Experts, 
Greeting of the day,
I am new to XML coding, and got stuck somewhere. 
Olease help me, I have one XML file with me, in which I want to change some 
text using excel macro. 
also the Replace what and Replace with text need to be taken from worksheet 
cells. 
I am attaching XML file as well Excel file for reference. 
Please help in, will be looking forward for quick response. 

-- 
Pankaj Pandey
Bhopal-- 
Are you =EXP(E:RT) or =NOT(EXP(E:RT)) in Excel? And do you wanna be? It’s 
=TIME(2,DO:IT,N:OW) ! Join official Facebook page of this forum @ 
https://www.facebook.com/discussexcel
 
FORUM RULES
 
1) Use concise, accurate thread titles. Poor thread titles, like Please Help, 
Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will not get 
quick attention or may not be answered.
2) Don't post a question in the thread of another member.
3) Don't post questions regarding breaking or bypassing any security measure.
4) Acknowledge the responses you receive, good or bad.
5) Jobs posting is not allowed.
6) Sharing copyrighted material and their links is not allowed.
 
NOTE : Don't ever post confidential data in a workbook. Forum owners and 
members are not responsible for any loss.
--- 
You received this message because you are subscribed to the Google Groups "MS 
EXCEL AND VBA MACROS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to excel-macros+unsubscr...@googlegroups.com.
To post to this group, send email to excel-macros@googlegroups.com.
Visit this group at https://groups.google.com/group/excel-macros.
For more options, visit https://groups.google.com/d/optout.


 
   -- 
Are you =EXP(E:RT) or =NOT(EXP(E:RT)) in Excel? And do you wanna be? It’s 
=TIME(2,DO:IT,N:OW) ! Join official Facebook page of this forum @ 
https://www.facebook.com/discussexcel
 
FORUM RULES
 
1) Use concise, accurate thread titles. Poor thread titles, like Please Help, 
Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will not get 
quick attention or may not be answered.
2) Don't post a question in the thread of another member.
3) Don't post questions regarding breaking or bypassing any security measure.
4) Acknowledge the responses you receive, good or bad.
5) Jobs posting is not allowed.
6) Sharing copyrighted material and their links is not allowed.
 
NOTE : Don't ever post confidential data in a workbook. Forum owners and 
members are not responsible for any loss.
--- 
You received this message because you are subscribed to the Google Groups "MS 
EXCEL AND VBA MACROS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to excel-macros+unsubscr...@googlegroups.com.
To post to this group, send email to excel-macros@googlegroups.com.
Visit this group at https://groups.google.com/group/excel-macros.
For more options, visit https://groups.google.com/d/optout.




-- 
Pankaj Pandey
Bhopal-- 
Are you =EXP(E:RT) or =NOT(EXP(E:RT)) in Excel? And do you wanna be? It’s 
=TIME(2,DO:IT,N:OW) ! Join official Facebook page of this forum @ 
https://www.facebook.com/discussexcel
 
FORUM RULES
 
1) Use concise, accurate thread titles. Poor thread titles, like Please Help, 
Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will not get 
quick attention or may not be answered.
2) Don't post a question in the thread of another member.
3) Don't post questions regarding breaking or bypassing any security measure.
4) Acknowledge the responses you receive, good or bad.
5) Jobs posting is not allowed.
6) Sharing copyrighted material and their links is not allowed.
 
NOTE : Don't ever post confidential data in a workbook. Forum owners and 
members are not responsible for any loss.
--- 
You received this message because you are subscribed to the Google Groups "MS 
EXCEL AND VBA MACROS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to excel-macros+unsubscr...@googlegroups.com.
To post to this group, send email to excel-macros@googlegroups.com.
Visit this group at https://groups.google.com/group/excel-macros.
For more options, visit https://groups.google.com/d/optout.


 
  

-- 
Are you =EXP(E:RT) or =NOT(EXP(E:RT)) in Excel? And do you wanna be? It’s 
=TIME(2,DO:IT,N:OW) ! Join official Facebook page of this forum @ 
https://www.facebook.com/discussexcel

FORUM RULES

1) Use concise, accurate thread titles. Poor thread titles, like Please Help, 
Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will not get 
quick attention or may not be answered.
2) Don't post a question in the thread of another member.
3) Don't post questions regarding breaking or bypassing any security measure.
4) Acknowledge the responses you receive, good or bad.
5) Jobs posting is not allowed.
6) Sharing copyrighted material and their links is not allowed.

NOTE  : Don't ever post confidential data in a workbook. Forum owners and 
members are not responsible for any loss.
--- 
You received this message because you are subscribed to the Google Groups "MS 
EXCEL AND VBA MACROS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to excel-macros+unsubscr...@googlegroups.com.
To post to this group, send email to excel-macros@googlegroups.com.
Visit this group at https://groups.google.com/group/excel-macros.
For more options, visit https://groups.google.com/d/optout.

Reply via email to