VBA Macros

Working with excel vba check boxes 

I have created a check box on a spread sheet and then named it AU from “Check Box 1″.

If I have selected AU checkbox then I am executing a command

More…

By Pavandeep Puddupakkam on March 7, 2010 | Excel, VBA Macros | A comment?
Tags: ,

How to run or execute a dos file or command using excel macro 

You will have to create a macro something like this:

Sub RunTest ()
Dim ReturnValue
ReturnValue = Shell("""C:\selenium\GoogleTest.bat"" ""G:iDO Messagingttermpromacrosbdf.ttl""", 1)
AppActivate ReturnValue
End Sub

Submitted by Pavandeep Puddupakkam

By Pavandeep Puddupakkam on February 25, 2010 | Software Testing, VBA Macros | A comment?

How to call a procedure or module in another procedure or module VBA Excel 

Here is the solution to call a procedure or module in another procedure or module VBA Excel.
Code from Module 1

Public Sub ScriptFooter(FileNum As Integer)
Print #FileNum, "</tbody></table>"
End Sub
Code from Module 2.
Public Sub CommandButton1_Click()
'code written on 21/01/2010 by Pavandeep Puddupakkam
Dim FileNum As Integer
Sheets("Search").Activate
FileNum = FreeFile ' next file number
Open "C:\XXX.txt" For Output As #FileNum ' creates the file if it doesn't exist
Call Module1.ScriptFooter(FileNum)
Close #FileNum ' close the file
End Sub

By Pavandeep Puddupakkam on January 28, 2010 | VBA Macros | A comment?

How to write a function and call a function in excel macros 

Here I am creating a function called  form1(FileNum As Integer) and calling the function in g() using Call form1(FileNum)

Sub form1(FileNum As Integer)
Workbooks.Open ("c:\test\test1.xlsx")
Sheets("Sheet1").Activate
Open "C:\test\test1.html" For Output As #FileNum ' creates the file if it doesn't exist
If Cells(1, 1) <> "" Then
Title = Cells(2, 2)
URL = Cells(1, 2)
Print #FileNum, Cells(1, 2)
Print #FileNum, "<title>"; Title; "</title>"
Print #FileNum, "</head>"
Else
Print #FileNum, "<body>"
End If
End Sub

More…

By Pavandeep Puddupakkam on January 23, 2010 | VBA Macros | A comment?

How to open a worksheet from another workbook 

In this example I am opening the worksheet Sheet2 from workbook test2.xls.
Sub q()
‘code written on 24/09/2008 by Pavandeep Puddupakkam
FileNum = FreeFile ‘ next file number
Open “C:\Hotfrog\test1.html” For Output As #FileNum ‘ creates the file if it doesn’t exist
Workbooks(“test2.xls”).Activate
Sheets(“Sheet2″).Activate
If Cells(1, 1) <> “” Then
Title = Cells(2, 2)
URL = Cells(1, 2)
Print #FileNum, Cells(1, 2)
Print #FileNum, “<title>”; Title; “</title>”
Print #FileNum, “</head>”
Else
Print #FileNum, “<body>”
Print #FileNum, “<table cellpadding=”; “”"1″”"; ” cellspacing=”; “”"1″”"; ” border=”; “”"1″”"; “>”
Print #FileNum, “<thead>”
Print #FileNum, “<tr><td rowspan=”; “”"1″”"; ” colspan=”; “”"3″”"; “>”; Title; “</td></tr>”
Print #FileNum, “</thead><tbody>”
End If
Close #FileNum ‘ close the file
End Sub

By Pavandeep Puddupakkam on January 22, 2010 | VBA Macros | A comment?

How to call a different workbook in Excel Macro 

In this example I am checking for the value in workbook test1.xls Sheet1.Cells(1, 2) and the calling the Sheet2 in workbook test2.xls

Sub q()
'code written on 22/01/2010 by Pavandeep Puddupakkam
'Dim FileNum As Integer
'Dim Title As String
Dim Sht As String
'Dim LastRow As Long, LastCol As Integer, r As Long
Sht = Sheets2
'LastRow = Sheet1.UsedRange.Rows(Sheet1.UsedRange.Rows.Count).Row
'LastCol = Sheet1.UsedRange.Columns(Sheet1.UsedRange.Columns.Count).Column
If Sheet1.Cells(1, 2) = "US" Then
Sheets("Sheet1").Activate
Else
Workbooks("test2.xls").Worksheets("Sheet2").Activate
End If
FileNum = FreeFile ' next file number
Open "C:\test\test1.html" For Output As #FileNum ' creates the file if it doesn't exist
If Cells(1, 1) <> "" Then
Title = Cells(2, 2)
URL = Cells(1, 2)
Print #FileNum, Cells(1, 2)
Print #FileNum, "<title>"; Title; "</title>"
Print #FileNum, "</head>"
Else
Print #FileNum, "<body>"
Print #FileNum, "<table cellpadding="; """1"""; " cellspacing="; """1"""; " border="; """1"""; ">"
Print #FileNum, "<thead>"
Print #FileNum, "<tr><td rowspan="; """1"""; " colspan="; """3"""; ">"; Title; "</td></tr>"
Print #FileNum, "</thead><tbody>"
End If
Close #FileNum ' close the file
End Sub

By Pavandeep Puddupakkam on | Excel, VBA Macros | A comment?