Question on ActiveX Script Task in Sql Server 2000 dts package - sql-server-2000

What does this line of code do
Set Pkg = DTSGlobalVariables.Parent
In the following ActiveX Script Task:
Function Main()
myfilename=inputbox( "Please enter the filename (ex. 2010Nov):")
Set Pkg = DTSGlobalVariables.Parent
DTSGlobalVariables("filename").Value=myfilename
Main = DTSTaskExecResult_Success
End Function
in a Sql Server dts package?

DTSGlobalVariables.Parent - the package object itself.
The script assigns it to your variable Pkg, but doesn't use it.

Related

Clear cells in multiple sheets from SSIS by VBA

How I can use below VBA coding in SSIS vba. I want to clear cells(data) from multiple sheets from SSIS by VBA coding
sub cod()
ThisWorkbook.Worksheets("Case management details").Range("A2:K10000").clear
ThisWorkbook.Worksheets("interface Timeliness").Range("A2:G20000").clear
ThisWorkbook.Worksheets("Life Events").Range("A2:N10000").clear
End sub
I had the same problem here. If you decided to solve this using SSIS component try with Script Task.
After you create excel steps will be:
Add Script Task on control flow.
Double click on component.
Press 'Edit Script...' button.
Right-click on the project in new visual studio windows (should be something like 'ST_' and some guid) and click on Manage NuGet Packages...
From 'Browse' tab install:
Microsoft.Office.Interop.Excel
Microsoft.CSharp
Into namespaces region add these 2 lines:
using Microsoft.Office.Interop.Excel;
using Microsoft.CSharp.RuntimeBinder;
Copy below code into ScriptMain class:
var appExcel = new Excel.Application();
string filename = #"D:\PathToExcel\ExcelFile.xlsx";
var newBook = appExcel.Workbooks.Open(filename);
var oSheet1 = newBook.Worksheets["Case management details"];
oSheet1.Range("A2", "K10000").Delete();
newBook.Save();
appExcel.Workbooks.Close();
appExcel.Quit();
Close without saving the second visual studio window (where you write script code).
Run the package
Note:
Instead of hardcoded file location, you can replace it with a package variable. In this case 2nd line will be:
string filename = Dts.Variables["User::ExcelFilePath"].Value.ToString();
I tested this package before write answer and everything work perfect!
With this logic, create multiple sheet instance and delete what you want.
If something isn't clear or non-logical write me in a comment and I will make correction.

Open Windows Command Script with VBA

Can I use a macro in Outlook to open a Windows Command Script file? The file I have is called Build_Order_File.CMD
I did try the Shell command but I got the error "Invalid procedure call or argument"
Here is what I tried
Dim Q2CFile
Q2CFile = Shell("C:\Users\SESA27956\Desktop\Build_Order_File.cmd", 1)
The attached image shows that it is expecting an = after the pathname.

How to call a vb method from command line?

Im trying to call a simple VB sub from windows task scheduler, the vb script is found inside a very large project so I have created a new item inside the project just to test the execution of the script. For now im just trying to return a simple string so that the process will go like this and this is also how I am going to be debugging and testing this:
Windows Task Scheduler > cmd line > .vb > sub/method
This is the test class I am working with for now.
Public Class clsSchedule
Public Sub RunTasksFromCommandLine(ByVal lstrArgs() As String)
Try
For i As Integer = 1 To lstrArgs.Length - 1 Step 1
lstrProcessKey = lstrArgs(i).Trim("-"c).Trim("/"c).ToUpper
Next i
End Try
End Sub
End Class
If you want to execute VBScript code from command line you can use mshta like in this example:
mshta vbscript:Execute("Msgbox(""Are you sure?"",vbYesNo+vbInformation,"""")(window.close)")
you can also check this - Is it possible to embed and execute VBScript within a batch file without using a temporary file?
If you want to execute VB.NET from command line... then may be you try with powershell codeblocks. If you want to embed VB.NET code into batch file you can use msbuild inline tasks or to use the .net compiler to create self-compiling script.

InstallShield - How to run installer using custom actions (VB script)

I have a package which binds my product and MATLAB run time as a dependency. The dependency should be installed only if its not present in target machine. I have selected deferred execution of a VB script (It should fire after File transfer).
Here's the code:
public function MatlabCheck()
Dim MATLABVal
MATLABVal = Session.property("MATLABROOT")
If Len(MATLABVal) = 0 Then
Set objShell = CreateObject("WScript.shell")
Dim cmd
cmd = Session.Property("INSTALLDIR\v1.0\dependencies\MCR_R2013b_win32_installer.exe")
objShell.run cmd
end if
end function
Note that I have put MATLABROOT property under Additional Requirements.
Using InstallShield Limited Edition on VS 2013.
I tried running this setup with the script integrated, however, it didn't work.

Create an excel file from DTS ActiveX Task

I need create ten different excel files from DTS ActiveX Task. Just create, not manipulated it. I just know that I have to use
CreateObject(Excel.Application)
and
CreateObject(Scripting.FileSystemObject)
Thanks for a while.
If you use SQL 2005+, see following URL
http://oakdome.com/programming/SSIS_ActiveXScript_to_ScriptTask.php
UPD. Added vbscript for file creation. Just use it in your DTS Script task
fileName = "d:\test_file.xls"
Set excelObj = CreateObject("Excel.Application")
excelObj.Visible = True
Set objWorkbook = excelObj.Workbooks.Add()
objWorkbook.SaveAs(fileName)
excelObj.Quit