• Here is my code, that I added to use variable....

    Imports System

    Imports System.Data

    Imports System.Math

    Imports Microsoft.SqlServer.Dts.Runtime

    Imports Microsoft.Office.Interop.Excel

    Imports System.IO

    Imports System.Text

    <System.AddIn.AddIn("ScriptMain", Version:="1.0", Publisher:="", Description:="")> _

    <System.CLSCompliantAttribute(False)> _

    Partial Public Class ScriptMain

    Inherits Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase

    Enum ScriptResults

    Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success

    Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure

    End Enum

    Public Sub Main()

    Dim vars As Variables 'New Added For Variable

    Dim oMissing As Object = System.Reflection.Missing.Value

    Dim xl As New Microsoft.Office.Interop.Excel.ApplicationClass()

    Dim xlBook As Microsoft.Office.Interop.Excel.Workbook

    Dim xlSheet As Microsoft.Office.Interop.Excel.Worksheet

    Dts.VariableDispenser.LockForRead("Filename") 'New Added For Variable

    'Start For Variable

    Dim File As String 'New Added For Variable

    File = CType(vars("Filename").Value, String) 'New Added For Variable

    'Dim laPath As String = "C:\Excel\ABC_dr_daily_lf_10-07-14.xls" 'My File Name

    Dim lapath As String = "File" 'New Added For Variable

    xlBook = DirectCast(xl.Workbooks.Open(laPath, oMissing, oMissing, oMissing, oMissing, oMissing, _

    oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, _

    oMissing, oMissing, oMissing), Workbook)

    xlSheet = DirectCast(xlBook.Worksheets.Item(1), Worksheet)

    xlSheet.Name = "Sheet1"

    xlBook.Save()

    xl.Application.Workbooks.Close()

    Dts.TaskResult = ScriptResults.Success

    End Sub

    End Class

    And I am using Variable = Filename READONLY IN Script Component.

    I am getting this error

    Error: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.NullReferenceException: Object reference not set to an instance of an object.

    at ST_916c6c3c7c75477199a83e3031243cae.vbproj.ScriptMain.Main()

    --- End of inner exception stack trace ---

    at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)

    at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)

    at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)

    at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)

    at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)

    at System.Type.InvokeMember(String name, BindingFlags invokeAttr, Binder binder, Object target, Object[] args, CultureInfo culture)

    at Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTATaskScriptingEngine.ExecuteScript()

    Please guide me, where I am doing wrong,

    Thank You.