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
Sub q()

'code written on 22/01/2010 by Pavandeep Puddupakkam
   Dim FileNum As Integer    
    FileNum = FreeFile ' next file number 
            Call form1(FileNum)
            Print #FileNum, Cells(2, 2)
     Close #FileNum ' close the file
    
End Sub

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by: wiki
Posted on: 1/23/2010 at 12:42 AM
Tags: , , , ,
Categories: VBA Macros
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (0) | Post RSSRSS comment feed

Add comment


 

  Country flag

biuquote
  • Comment
  • Preview
Loading