Hi all,
I posted something similar in the past. Thank you Andrzejek (Andy) for your help.
This is a little different.
I have a signature file I constantly modify. If my cursor is anywhere on a specific row, I want to find and replace text to the template variables NAME, ASSETTAG, SERIALNUMBER, and HARDWAREDESCRIPTION. However, if I highlight numerous rows, I want to repeat the search create the output as shown below. The trick for me is the repeatability. I can do it for one row, but not multiple rows.
There is a sample of Code I currently use, but I need to be able to repeat for n rows. The rest if the signature is fine. It's just the table rows I need to repeat.
Here is the current code for single row output:
Sub EmailSignature()
Dim strInputData As String
Dim strOutputData As String
Dim i As Integer
Dim path As String
path = (Environ$("USERPROFILE"))
Open path & "\appdata\roaming\microsoft\signatures\Ship.tmp" For Input As #1
strInputData = Input$(LOF(1), 1)
Close #1
i = ActiveCell.Row
' Do While Range("A" & i).Value <> ""
strOutputData = strInputData
strOutputData = Replace(strOutputData, "FIRSTNAME", Range("E" & i).Value)
'strOutputData = Replace(strOutputData, "LASTNAME", Range("B" & i).Value)
strOutputData = Replace(strOutputData, "ADDRESS1", Range("F" & i).Value)
strOutputData = Replace(strOutputData, "ADDRESS2", Range("G" & i).Value)
strOutputData = Replace(strOutputData, "PHONENUMBER", Range("H" & i).Value)
strOutputData = Replace(strOutputData, "REGARDING", Range("I" & i).Value)
strOutputData = Replace(strOutputData, "WORKTRACK", Range("J" & i).Value)
strOutputData = Replace(strOutputData, "TRACKINGNUMBER", Range("Z" & i).Value)
strOutputData = Replace(strOutputData, "REQUESTER", Range("B" & i).Value)
strOutputData = Replace(strOutputData, "ASSETTAG", Range("N" & i).Value)
strOutputData = Replace(strOutputData, "SERIALNUMBER", Range("M" & i).Value)
strOutputData = Replace(strOutputData, "HARDWAREDESCRIPTION", Range("L" & i).Value)
Open path & "\appdata\roaming\microsoft\signatures\Ship.htm" For Output As #1
Print #1, strOutputData
Close #1
' i = i + 1
'Loop
End Sub
Excel Spreadsheet sample:
A B C D
1 Asset tag Serial Number Hardware description Name
2 70000001 ABCDEFG ROUTER George
3 70000002 ZYXWVUT SWITCH George
4 70000003 QWERTY COMPUTER George
Template sample
Signature.tmp
<html>
<head>
<style>
table, th, td {
border: 1px solid black;
}
</style>
</head>
Hi NAME, the hardware is being shipped as requested
<table style="width:100%">
<tr>
<td>Asset tag</td>
<td>Serial Number</td>
<td>Hardware description</td>
</tr>
<tr>
<td>ASSETTAG</td>
<td>SERIALNUMBER</td>
<td>HARDWAREDESCRIPTION</td>
</tr>
</table>
</html>
Output 1 sample:
Signature.htm
<html>
<head>
<style>
table, th, td {
border: 1px solid black;
}
</style>
</head>
Hi George, the hardware is being shipped as requested
<table style="width:100%">
<tr>
<td>Asset tag</td>
<td>Serial Number</td>
<td>Hardware description</td>
</tr>
<tr>
<td>70000001</td>
<td>ABCDEFG</td>
<td>TELEVISION</td>
</tr>
</table>
</html>
Output 1 sample (as viewed in browser)
Hi George, the hardware is being shipped as requested
Asset tag Serial Number Hardware description
70000001 ABCDEFG ROUTER
Output 2 sample
Signature.htm
<html>
<head>
<style>
table, th, td {
border: 1px solid black;
}
</style>
</head>
Hi George, the hardware is being shipped as requested
<table style="width:100%">
<tr>
<td>Asset tag</td>
<td>Serial Number</td>
<td>Hardware description</td>
</tr>
<tr>
<td>70000001</td>
<td>ABCDEFG</td>
<td>ROUTER</td>
</tr>
<tr>
<td>700000002</td>
<td>ZYXWVUT</td>
<td>SWITCH</td>
</tr>
<tr>
<td>700000003</td>
<td>QWERTY</td>
<td>COMPUTER</td>
</tr>
</table>
</html>
Output 2 sample (as viewed in browser or signature)
Hi George,
the hardware is being shipped as requested.
Asset tag Serial Number Hardware description
70000001 ABCDEFG ROUTER
70000002 ZYXWVUT SWITCH
70000003 QWERTY COMPUTER
Thank you
Phil Breau
I posted something similar in the past. Thank you Andrzejek (Andy) for your help.
This is a little different.
I have a signature file I constantly modify. If my cursor is anywhere on a specific row, I want to find and replace text to the template variables NAME, ASSETTAG, SERIALNUMBER, and HARDWAREDESCRIPTION. However, if I highlight numerous rows, I want to repeat the search create the output as shown below. The trick for me is the repeatability. I can do it for one row, but not multiple rows.
There is a sample of Code I currently use, but I need to be able to repeat for n rows. The rest if the signature is fine. It's just the table rows I need to repeat.
Here is the current code for single row output:
Sub EmailSignature()
Dim strInputData As String
Dim strOutputData As String
Dim i As Integer
Dim path As String
path = (Environ$("USERPROFILE"))
Open path & "\appdata\roaming\microsoft\signatures\Ship.tmp" For Input As #1
strInputData = Input$(LOF(1), 1)
Close #1
i = ActiveCell.Row
' Do While Range("A" & i).Value <> ""
strOutputData = strInputData
strOutputData = Replace(strOutputData, "FIRSTNAME", Range("E" & i).Value)
'strOutputData = Replace(strOutputData, "LASTNAME", Range("B" & i).Value)
strOutputData = Replace(strOutputData, "ADDRESS1", Range("F" & i).Value)
strOutputData = Replace(strOutputData, "ADDRESS2", Range("G" & i).Value)
strOutputData = Replace(strOutputData, "PHONENUMBER", Range("H" & i).Value)
strOutputData = Replace(strOutputData, "REGARDING", Range("I" & i).Value)
strOutputData = Replace(strOutputData, "WORKTRACK", Range("J" & i).Value)
strOutputData = Replace(strOutputData, "TRACKINGNUMBER", Range("Z" & i).Value)
strOutputData = Replace(strOutputData, "REQUESTER", Range("B" & i).Value)
strOutputData = Replace(strOutputData, "ASSETTAG", Range("N" & i).Value)
strOutputData = Replace(strOutputData, "SERIALNUMBER", Range("M" & i).Value)
strOutputData = Replace(strOutputData, "HARDWAREDESCRIPTION", Range("L" & i).Value)
Open path & "\appdata\roaming\microsoft\signatures\Ship.htm" For Output As #1
Print #1, strOutputData
Close #1
' i = i + 1
'Loop
End Sub
Excel Spreadsheet sample:
A B C D
1 Asset tag Serial Number Hardware description Name
2 70000001 ABCDEFG ROUTER George
3 70000002 ZYXWVUT SWITCH George
4 70000003 QWERTY COMPUTER George
Template sample
Signature.tmp
<html>
<head>
<style>
table, th, td {
border: 1px solid black;
}
</style>
</head>
Hi NAME, the hardware is being shipped as requested
<table style="width:100%">
<tr>
<td>Asset tag</td>
<td>Serial Number</td>
<td>Hardware description</td>
</tr>
<tr>
<td>ASSETTAG</td>
<td>SERIALNUMBER</td>
<td>HARDWAREDESCRIPTION</td>
</tr>
</table>
</html>
Output 1 sample:
Signature.htm
<html>
<head>
<style>
table, th, td {
border: 1px solid black;
}
</style>
</head>
Hi George, the hardware is being shipped as requested
<table style="width:100%">
<tr>
<td>Asset tag</td>
<td>Serial Number</td>
<td>Hardware description</td>
</tr>
<tr>
<td>70000001</td>
<td>ABCDEFG</td>
<td>TELEVISION</td>
</tr>
</table>
</html>
Output 1 sample (as viewed in browser)
Hi George, the hardware is being shipped as requested
Asset tag Serial Number Hardware description
70000001 ABCDEFG ROUTER
Output 2 sample
Signature.htm
<html>
<head>
<style>
table, th, td {
border: 1px solid black;
}
</style>
</head>
Hi George, the hardware is being shipped as requested
<table style="width:100%">
<tr>
<td>Asset tag</td>
<td>Serial Number</td>
<td>Hardware description</td>
</tr>
<tr>
<td>70000001</td>
<td>ABCDEFG</td>
<td>ROUTER</td>
</tr>
<tr>
<td>700000002</td>
<td>ZYXWVUT</td>
<td>SWITCH</td>
</tr>
<tr>
<td>700000003</td>
<td>QWERTY</td>
<td>COMPUTER</td>
</tr>
</table>
</html>
Output 2 sample (as viewed in browser or signature)
Hi George,
the hardware is being shipped as requested.
Asset tag Serial Number Hardware description
70000001 ABCDEFG ROUTER
70000002 ZYXWVUT SWITCH
70000003 QWERTY COMPUTER
Thank you
Phil Breau