Thursday, 15 September 2016

VBScript: Function Returning Array



Function Getdata()

Dim a()
strt = "sumit"
strt2 = "raut"
a = Array(strt, strt2)

Getdata = a()


End Function

Sub main()


Dim oExcel, oWB, oSheet, setVal
Set oExcel = CreateObject("Excel.Application")
Set oWB = oExcel.Workbooks.Open("D:\Macrowork\Call from Sub.xlsx")
Set oSheet = oWB.WorkSheets("data")
oExcel.Visible = True
Dim Arr1()

rowcount = oSheet.usedrange.rows.Count

For r = 2 To rowcount Step 1

Arr1 = Getdata
oSheet.cells(r, 4) = Arr1(0)
oSheet.cells(r, 5) = Arr1(1)

Next

oWB.Save
Set oExcel = Nothing

End Sub


Sunday, 11 September 2016

MSWord: Posting Images in Word Document via Vbscript

Set objWord = CreateObject("Word.Application")
objWord.Visible = True
Set objDoc = objWord.Documents.Add()
Set objSelection = objWord.Selection

'Set objRang = objDoc.Range()
Set objShape = objDoc.inlineShapes

''Add Picture to word file
fname="C:\Users\Public\Pictures\Sample Pictures\Koala.jpg"
fname2="C:\Users\Public\Pictures\Sample Pictures\Tulips.jpg"
objShape.AddPicture (fname)
objWord.Selection.MoveDown 1,0
objWord.Selection.TypeParagraph()

objShape.AddPicture (fname2)
objWord.Selection.MoveDown 1,0
objWord.Selection.TypeParagraph()

''Save Word File
objDoc.saveas("C:\Users\sunshine\Desktop\Test.docx")

Friday, 9 September 2016

VBscript:Sorting Numbers in Descending Order

dim a
a=array(1,5,6,7,8,9,0)
ub=ubound(a)
lb=lbound(a)

For i=lb to ub-1 Step 1



   For j=lb+i  to ub  Step 1
        if a(i)<a(j) then
         temp=a(j)
         a(j)=a(i)
         a(i)=temp
        end if
    Next


Next


'Print Sorted Array

for i=lbound(a) to ubound(a) Step 1
msgbox a(i)

Next







Saturday, 3 September 2016

Vbscript:Skipping Iteration in a loop

function writefail(r)
oSheet.cells(r,5).value="INVALID as P"

End function


Dim oExcel, oWB, oSheet, getVal
Set oExcel=CreateObject("Excel.Application")
Set oWB=oExcel.Workbooks.Open("C:\Users\sunshine\Desktop\Macro\Data.xlsx")
Set oSheet=oWB.WorkSheets("Sheet1")
oExcel.Visible=TRUE

for r =2 to 14

status=oSheet.cells(r,4).value

if status="P" then oSheet.cells(r,5).value="INVALID as P"

'if status="P" then writefail(r)
do

'if status="P" then _
'writefail(r)
'exit do



'if status="P" then _
'oSheet.cells(r,5).value="INVALID as P" exit do
'loop while false

if status="P" then exit do

if status<>"P" then _
oSheet.cells(r,6).value="V1"
oSheet.cells(r,7).value="V2"
'oSheet.cells(r,5).value="VALID"
exit do
'loop while false
loop while r<6

Next

oWB.save
set oExcel=nothing




Spring Boot : Exception Handler 14