With below code I'm trying to add a anchor tag/hyperlink to a number in html file. Though I can see correct values in Local Window, same are not updated in file. Don't know what's wrong.
Sub HyperlinkPRs() '''https://stackoverflow.com/questions/10434335/text-file-in-vba-open-find-replace-saveas-close-file
Dim rng As Range
Dim sBuf As String
Dim sTemp As String
Dim iFileNum As Integer
Dim sFileName As String
Dim var As String
lr = Worksheets("RawData").Cells(Rows.Count, 7).End(xlUp).Row
Set rng = Sheets("RawData").Range("G2:G" & lr)
' Edit as needed
sFileName = ThisWorkbook.Path & "\" & "data.html"
iFileNum = FreeFile
Open sFileName For Input As iFileNum
Do Until EOF(iFileNum)
Line Input #iFileNum, sBuf
sTemp = sTemp & sBuf & vbCrLf
Loop
Close iFileNum
''' Replace code
For i = 1 To lr
pr = Sheets("RawData").Range("G" & i).Value
link = "<a href=""" & _
"www.xyz.com/cgi-binr.pl?entry=" & _
pr & _
""">" & _
pr & _
"</a>" & "</td>"
sTemp = Replace(sTemp, pr & "</td>", link)
Next
iFileNum = FreeFile
Open sFileName For Output As iFileNum
Print #iFileNum, sTemp
Close iFileNum
End Sub
Values from local window (correct):
pr: 9525027
link = <a href="www.xyz.com/cgi-binr.pl?entry=9525027">9525027</a></td>
Replaced with:
9525027<a href="www.xyz.com/cgi-binr.pl?entry="></a></td>
Input in text file:
<td class=xl6516703 style='border-top:none;border-left:none'> </td>
<td class=xl6516703 style='border-top:none;border-left:none'> </td>
<td class=xl6516703 style='border-top:none;border-left:none'> </td>
<td class=xl6516703 style='border-top:none;border-left:none'> </td>
<td class=xl6516703 style='border-top:none;border-left:none'>14</td>
<td class=xl6516703 style='border-top:none;border-left:none'>24</td>
<td class=xl7616703 style='border-top:none;border-left:none'>9525027</td>
Output:
<td class=xl6516703 style='border-top:none;border-left:none'> <a
href="www.xyz.com_pr.pl?entry="></a></td>
<td class=xl6516703 style='border-top:none;border-left:none'> <a href="www.xyz.com_pr.pl?entry="></a></td>
<td class=xl6516703 style='border-top:none;border-left:none'> <a href="www.xyz.com_pr.pl?entry="></a></td>
<td class=xl6516703 style='border-top:none;border-left:none'> <a href="www.xyz.com_pr.pl?entry="></a></td>
<td class=xl6516703 style='border-top:none;border-left:none'>14<a href="www.xyz.com_pr.pl?entry="></a></td>
<td class=xl6516703 style='border-top:none;border-left:none'>24<a href="www.xyz.com_pr.pl?entry="></a></td>
<td class=xl7616703 style='border-top:none;border-left:none'>9525027<a href="www.xyz.com_pr.pl?entry="></a></td>