Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 23-01-2010
Member
 
Join Date: Aug 2006
Posts: 222
How to Create Macro in VBA program?

I am new to VBA programming. I have to create a macro in VBA program. I want to create Macro so that I can do the basic stuff like inserting data, changing data etc. Also tell me that is there any way, where when i click it a box pops up asking questions about what data to input.? The main thing I want to ask is that how to create a macro in VBA program.?? Please help me as soon as possible.!
__________________
Just a reply to say thank you for these links and posts I have a lot to read and learn now!


Reply With Quote
  #2  
Old 23-01-2010
Member
 
Join Date: Apr 2008
Posts: 1,948
Re: How to Create Macro in VBA program?

If you want to create a Macro, you can follow the given steps :
  1. Go to the option Tools after opening the Visual Basic Editor. Then go to the Macro option in Tools. And then go to Visual Basic Editor. There is also a short cut key for this, you can press [Alt] and [F11] keys at the same time and can reach to the same place.
  2. On top of the Visual Basic Editor, you will find the Insert menu, click on that and select Module to open the Module window, where you write the codes.
  3. Now in the Module window, type the following code :
    Code:
    // Example of Hello World
    Sub showMessage()
        MsgBox "Hello World!"
    End Sub
  4. Then go to the Run Sub/UserForm to run the program or you can also press F5 for running the program.
  5. After doing this, the message box pops up with the "Hello World!" greeting.
Reply With Quote
  #3  
Old 23-01-2010
Member
 
Join Date: May 2008
Posts: 2,008
Re: How to Create Macro in VBA program?

Before creating a macro, you should be having knowledge about the Modules and Procedures. I have tried to explain you the Scope of the Modules and Procedures. A module is a container for procedures. Whereas the procedure is a unit of code enclosed between the Sub and End Sub statement. Also the procedure can be enclosed between Function and End Function statements. I have given an example of the procedure, that will print the current date and time on cell F5:
Code:
Sub ShowTime()
    Range("F5") = Now()
End Sub
The following function is for adding the two numbers :
Code:
Function sumNo(x, y)
     sumNo = x + y
End Function
Reply With Quote
  #4  
Old 23-01-2010
Member
 
Join Date: May 2008
Posts: 2,293
Re: How to Create Macro in VBA program?

According to me you can use the InputBox function to display the dialog box. The user can write some input and click on a button on the dialog box displayed by the InputBox function. For example, if the user clicks the OK button or presses ENTER on the keyboard, the InputBox function will return the text in the text box. Similarly, the function will return an empty string (""), if the user clicks on the Cancel button. The syntax for the InputBox function is :
Code:
InputBox(prompt[,title][,default][,xpos][,ypos][,helpfile,context])
Reply With Quote
  #5  
Old 23-01-2010
Member
 
Join Date: Nov 2008
Posts: 996
Re: How to Create Macro in VBA program?

I have provided the code for defining the scope for procedure.
Code:
Public Sub ShowTime()
    Range("C1") = Now()
End Sub

Private Sub ShowTime()
    Range("C1") = Now()
End Sub
Hope that it will help you to understand the concepts of procedure.
Reply With Quote
  #6  
Old 23-01-2010
Member
 
Join Date: Mar 2008
Posts: 672
Re: How to Create Macro in VBA program?

For creating a Button to open the Excel UserForm, follow the steps :
Activate the PartLocDB.xls workbook after switching to Excel.
  1. Double-click on the sheet tab for Sheet2.
  2. You will have to type "Parts Data Entry".
  3. After typing the above lines, press enter.
  4. Click on the Rectangle tool present on the Drawing toolbar.
  5. Draw a rectangle in the center of the worksheet and then use the format as desired.
  6. Type "To Add Part Information, Click Here" with the rectangle selected.
  7. Then choose 'Assign Macro' by doing the right click on the rectangle border.
  8. Click the New button.
  9. Type "frmPartLoc.Show" where your cursor is flashing.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "How to Create Macro in VBA program?"
Thread Thread Starter Forum Replies Last Post
PLEASE help create a quick program? No idea how. colgan37 Software Development 1 20-04-2011 05:46 PM
Procedure to create Auto-Run Macro Bottlenecked Windows Software 5 07-01-2010 02:01 PM
How can I create a macro in microsoft PowerPoint? Prashobh Mallu Windows Software 5 05-01-2010 02:09 PM
How to create a macro in Excel Bhadrak Windows Software 3 06-05-2009 03:13 PM
create a program to block access to a folder DeMenAce Software Development 2 15-01-2009 06:52 PM


All times are GMT +5.5. The time now is 08:15 PM.