Hi All,
Can anyone help me with finding and replacing text inside textbox of excel using dotnet expression
Am using Invoke code activity and am able to enter values in excel cells but unable to replace values in Textbox of Excel β¦ Below is the code am using β¦ Thanks for your help in advance
Dim ExcelApp As Microsoft.Office.Interop.Excel.Application
Dim WB As Microsoft.Office.Interop.Excel.Workbook
Dim WS As Microsoft.Office.Interop.Excel.Worksheet
Dim Textbox As Microsoft.Office.Interop.Excel.Shapes
ExcelApp = New Microsoft.Office.Interop.Excel.Application
WB = ExcelApp.Workbooks.Open(filePath)
WS = CType(WB.Sheets(sheetName),Microsoft.Office.Interop.Excel.Worksheet)
WS.Activate
WS.Range(βA1β).Value=CompanyName
WS.Range(βE2β).Value=Address
WS.Range(βE3β).Value=ZipCode
WS.Range(βE4β).Value=Tlf
WS.Range(βG3β).Value=VATID
If TeleFax<>ββ Then
WS.Range(βH2β).Value=TeleFax
WS.Range(βG2β).Value=βTeleFaxβ
End If
WB = ExcelApp.Workbooks.Open(filePath)
WS = CType(WB.Sheets(sheetName),Microsoft.Office.Interop.Excel.Worksheet)
'Textbox = WS.Shapes.Range(βTextBox 1β)
Try
TextReplacement = Nothing
Dim ExcelApp As Microsoft.Office.Interop.Excel.Application
Dim WB As Microsoft.Office.Interop.Excel.Workbook
Dim WS As Microsoft.Office.Interop.Excel.Worksheet
Dim shp As Microsoft.Office.Interop.Excel.Shape
Dim Old_Str_Text As String
Dim New_Str_Text As String
ExcelApp = New Microsoft.Office.Interop.Excel.Application
WB = ExcelApp.Workbooks.Open(filePath)
WS = CType(WB.Sheets(sheetName),Microsoft.Office.Interop.Excel.Worksheet)
WS.Activate
WS.Range(βA1β).Value=CompanyName
WS.Range(βE2β).Value=Address
WS.Range(βE3β).Value=ZipCode
WS.Range(βE4β).Value=Tlf
WS.Range(βG3β).Value=VATID
If TeleFax<>ββ Then
WS.Range(βH2β).Value=TeleFax
WS.Range(βG2β).Value=βTeleFaxβ
End If
For Each shp In WS.Shapes
Old_Str_Text = shp.TextFrame.Characters.Text
New_Str_Text = Old_Str_Text.Replace(β{Company Name}β, CompanyName).Replace(β{Country}β, CountryName).Replace(β{VAT Text}β, VATText).Replace(β{Month}β, MonthYear)
shp.TextFrame.Characters.Text = New_Str_Text
Next
ExcelApp.DisplayAlerts = False
ExcelApp.Visible = True
TryCast(WB.Sheets(sheetToDelete),Microsoft.Office.Interop.Excel.Worksheet).Delete()
WB.SaveAs(fileName, FileFormat:=51)
WB.Close
Catch e As Exception
TextReplacement = e
End Try