vrunda
Member
I have a vb code which I want to convert into vba to work in excel
Code:
Private Function LedgerMasterText(ByVal intI As Integer) As String Dim strTemp As String
Dim strTxt As String
sbExport.SimpleText = intI & ": " & Trim$(xlWS.Cells(intI, 2)) strTxt = vbNullString
strTxt = _
"<ENVELOPE>" & vbCrLf & _ "<HEADER>" & vbCrLf & _
"<VERSION>1</VERSION>" & vbCrLf & _ "<TALLYREQUEST>Import </TALLYREQUEST>" & vbCrLf & _ "<TYPE>Data</TYPE>" & vbCrLf & _
"<ID>All Masters</ID>" & vbCrLf & _ "</HEADER>" & vbCrLf & _
"<BODY>" & vbCrLf & _ "<DESC>" & _
"<STATICVARIABLES>" & _ "<SVCURRENTCOMPANY>" & _
"##SVCurrentCompany" & _
"</SVCURRENTCOMPANY>" & _
"</STATICVARIABLES>" & _
"</DESC>" & _
"<DATA>" & vbCrLf & _
"<TALLYMESSAGE>" & vbCrLf & _ "<LEDGER>" & vbCrLf & _ "<NAME.LIST>" & vbCrLf & _
"<NAME>" & ReplaceXmlText(Trim$(xlWS.Cells(intI, 2))) & "</NAME>" & vbCrLf
If Trim$(xlWS.Cells(intI, 1)) <> vbNullString Then
strTxt = strTxt & "<NAME>" & ReplaceXmlText(Trim$(xlWS.Cells(intI, 1))) & "</NAME>" & vbCrLf
End If
strTxt = strTxt & _
"</NAME.LIST>" & vbCrLf & _
"<PARENT>" & ReplaceXmlText(Trim$(xlWS.Cells(intI, 3))) & "</PARENT>" & vbCrLf
'-----Optional----------
If Trim$(xlWS.Cells(intI, 4)) <> vbNullString Then
strTxt = strTxt & "<ADDRESS.LIST>" & vbCrLf
strTxt = strTxt &
"<ADDRESS>" & ReplaceXml Text(Trim$(xlWS.Cells(intI, 4))) & "</ADDRESS>" _ & vbCrLf 'Address 1
If Trim$(xlWS.Cells(intI, 5)) <> vbNullString Then
strTxt = strTxt & _
"<ADDRESS>" & ReplaceXmlText(Trim$(xlWS.Cells(intI, 5))) &
"</ADDRESS>" & vbCrLf 'Address 2
If Trim$(xlWS.Cells(intI, 6)) <> vbNullString Then
strTxt = strTxt & _
"<ADDRESS>" & ReplaceXmlText(Trim$(xlWS.Cells(intI, 6))) & "</ADDRESS>" & vbCrLf 'Address 3
strTxt = strTxt & "</ADDRESS.LIST>" & vbCrLf
End If
If Trim$(xlWS.Cells(intI, 7)) <> vbNullString Then strTxt = strTxt & _
"<STATENAME>" & ReplaceXmlText(Trim$(xlWS.Cells(intI, 7))) &
"</STATENAME>"
End If
If Trim$(xlWS.Cells(intI, 8)) <> vbNullString Then strTxt = strTxt &
"<LEDGERPHONE>" & ReplaceXmlText(Trim$(xlWS.Cells(intI, 8))) & _ "</LEDGERPHONE>"
End If
If Trim$(xlWS.Cells(intI, 9)) <> vbNullString Then strTxt = strTxt &
"<LEDGERFAX>" & ReplaceXmlText(Trim$(xlWS.Cells(intI, 9))) & _ "</LEDGERFAX>"
End If
If Trim$(xlWS.Cells(intI, 10)) <> vbNullString Then strTxt = strTxt &
"<EMAIL>" & ReplaceXmlText(Trim$(xlWS.Cells(intI, 10))) & _ "</EMAIL>"
End If
strTemp = ReplaceXmlText(Trim$(xlWS.Cells(intI, 2))) strTxt = strTxt &
"<ADDITIONALNAME>" & Trim$(strTemp) & _ "</ADDITIONALNAME>" & _ vbCrLf
strTxt = strTxt & _ "</LEDGER>" & vbCrLf & _
"</TALLYMESSAGE>" & vbCrLf & _ "</DATA>" & vbCrLf & _
"</BODY>" & vbCrLf & _ "</ENVELOPE>" & vbCrLf
LedgerMasterText = strTxt End Function