For some reason, we can not use [BalaReva.Excel.Activities.] to rename sheet.
So I wrote a invoke code to resolve this problem.
But I encounter a [: Error compiling code ] mentioned that :
error BC30574: Option Strict On では、遅延バインディングを使用できません。 At line 30
I tried to work on this by many method,but no result.
Please help.
Here is my code:::
Dim InvokeProp As Func(Of Object, String, Object(), Object) = _
Function(target As Object, ParamName As String, Args As Object()) As Object
Return target.GetType().InvokeMember(ParamName, Reflection.BindingFlags.GetProperty Or Reflection.BindingFlags.Instance, Nothing, target, Args)
End Function
Dim InvokeMethod As Func(Of Object, String, Object(), Object) = _
Function(target As Object, ParamName As String, Args As Object()) As Object
Return target.GetType().InvokeMember(ParamName, Reflection.BindingFlags.InvokeMethod Or Reflection.BindingFlags.Instance, Nothing, target, Args)
End Function
Dim InvokePropSet As Func(Of Object, String, Object(), Object) = _
Function(target As Object, ParamName As String, Args As Object()) As Object
Return target.GetType().InvokeMember(ParamName, Reflection.BindingFlags.SetProperty Or Reflection.BindingFlags.Instance, Nothing, target, Args)
End Function
Dim ReleaseObj As Action(Of Object) = _
Sub(target As Object)
Runtime.InteropServices.Marshal.ReleaseComObject(target)
End Sub
Dim xlApp As Object = CreateObject("Excel.Application")
Dim xlBooks As Object = InvokeProp(xlApp, "WorkBooks", Nothing)
Dim xlBook As Object = InvokeMethod(xlBooks, "Open", New Object(0) {TargetFile})
Dim targetWorkSheets As Object = InvokeProp(xlBook, "WorkSheets", Nothing)
Dim paraName As Object = New Object(0){TargetSheetName}
targetWorkSheets(0).InvokeMember("Name",Reflection.BindingFlags.SetProperty, Nothing,paraName)
ReleaseObj(targetWorkSheets)
InvokeMethod(xlBook, "Close", New Object(0) {False})
ReleaseObj(xlBook)
ReleaseObj(xlBooks)
InvokeMethod(xlApp, "Quit", Nothing)
ReleaseObj(xlApp)