Class Modules?
Oct 14, 2008I'm wondering about class modules and what they can be used for etc etc? i want to continue developing my VBA and feel that this area is the next step?
View 2 RepliesI'm wondering about class modules and what they can be used for etc etc? i want to continue developing my VBA and feel that this area is the next step?
View 2 Repliesi've reached a point where i would like to learn more about class modules but i have no resources. When i create a Class object can i visually see it? i want to know as i'm looking to use them within userforms if possible
View 4 Replies View RelatedI have a problem with a dynamic userform that I need to create.
I need a userform in which the number of controls are determined by the some values in the worksheet. The users of the workbook must be able to add new controls to the form, so I do not know the number of controls in advance. I therefore can not create the userform through the design module but must create it through code instead.
I need a userform with a number of comboboxes and a commandbutton, which when clicked sends the content of the comboboxes to the first empty row in a worksheet.
My problem is that I can't assign any commands to the comboboxes (which are created at runtime), nor can I use the values of the comboboxes in any commands assigned to other controls in the userform (e.g. the commandbutton).
I have read as far that I probably need some form of class module to create the controls at runtime, but since I am relatively new at VBA, I'm having trouble getting the class module to work in connection with the userform.
I am working with a class module and some fields require specific inputs that another coder may not intuitively know. How can I create a list of acceptable conastants that will appear as a drop down when the user is coding with the custom object?
For example:
I am creating an Email Engine object that will handle all my emailing needs in code, because coding emails is such a pain. Then I can just create the blasted thing, import the class module where needed and never have to worry about it again. Some coworkers are interested in using the module for their projects when I am finished. I want to put an option for message flags in the object, but only certain colored flags are allowed. How can I get the VBE to show a little drop down with the acceptable flag constants when another user types
[Object Variable].MessageFlagColor = {drop down list of options}
I started with
Public Property Let MessageFlagColor(Value As Constants)
End Property
But that hasn't gotten me anywhere.
I've created a class called CStock. It has 5 standard properties (with Get/Let methods) as explained in that article above. Nothing fancy here.
I also want to create a CPortfolio class that has 3 properties: pName, pNumberofPositions, and pHoldings. the first 2 are stardard, but the last one is different. I want it to somehow keep a collection of stocks.
I've created two modules, card and pack. Card has three variables (value, name, suit) and pack is made up of an array of 52 cards. Referencing it from a test module (NOT a class module) I expected to be able to use debug.print pack.card(32).suit to return the suit of the 32nd card. Instead I get an error message "Object or With variable not set". What am I doing wrong
Private p_strSuit As String
Private p_strName As String
Private p_iValue As Integer
Public Property Let Suit(strSuit As String)
p_strSuit = strSuit
End Property
Public Property Get Suit() As String
Suit = p_strSuit
End Property
Public Property Let Name(strName As String)
p_strName = strName
End Property......................................
Can i know how many modules can be used in a VBA Program
View 9 Replies View RelatedI have managed to get it almost done with lots of help from here the last issue I have is this:
The module I want transferred is working the assigning of the macro within that module to the button is working, however, when it gets to the FillSalesSheet section it opens the said workbook but then jumps to the module and the FillSalesSheet in that.
Module 1 which I would like ignored on the newly formed workbooks looks like this: ...
It seems like I am asking a question at least once a day. I searched the net and forums and could not find an answer to this question. Thanks to everyone for the help I am making a lot of progress because all of you. Basically, I have a read-only workbook which the user gets a prompt to save as a new workbook for editing purposes. I have a autorun macro so now when the user opens their workbook, it contains my autorun macro. I do not want this. Is there a way to remove modules so that the users copy has no macro information?
View 9 Replies View RelatedI have two modules I wish to run when I open a workbook. The reason I have them as modules is they are required to be run manually, also.
Is it possible for me to set a Workbook_Open() sub that will run these two modules?
The modules names are Module1 and Module2.
The modules stipulate what sheets etc they have to act on, I only need the modules to be initiated.
I'm trying to produce a spreadsheet that pulls infomation from different web pages throughout the day. It needs to pull quite a large amount of information from different web pages hence I wanted to produce a subroutine which could be called with different variables for each web page, i.e. url, field, destination, etc.
To actually produce the query I recorded a macro and then used the code it produced. I then changed the URL to url, a string variable which holds the urls of the pages. The destion address was changed to destination, a range variable to store the destionation location, and the webTable was changed to table also a string variable to store the table number. This is shown below.
With ActiveSheet.QueryTables.Add(Connection:= _
url, Destination:= destination)
.Name = "q?s=%5EFTSE&m=L_137"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True.............................
I had a search and look around, but couldn't find any information on how to quickly (automatedly) export all the modules in a workbook to text files.
View 3 Replies View RelatedI was looking for code that actually deletes ALL modules in the VBA code after I terminate a particular program.
View 2 Replies View RelatedI'm trying to make it so that a lastrow I defined in one module will still be defined in another macro.
My background for this - my macro is too large for one module, therefore, I split it in two. However, the new module uses defined variables (multiple lastrow definitions) from the original module.
So, is there a way to make it so when I originally define a lastrow in one module, other modules will recognize it?
I have a number of modules that I want to call is it possible to call them from an array
For example
myarray = Array("Outstanding_Per_Agent", "Unique_Records")
Call myarray
This doesn't work as it says it expects a sub function or property
Do I need to define "myarray" as something or is it even possible.
I'm working with a substantial amount of code (which, due to its size, has been spread out into different modules). Whenever I transition from one module to the other, I have placed a msg at the beginning of each module to prompt the user to simply insert an integer to signify which version of the automation that is run. The following is an excerpt of a sample msg
[CODE]
Dim Msg, Title As String
Dim MyInput As Integer
' Define message."
[Code].....
Where, whatever report is being run, will be the same throughout all of the modules (for example, if you run the "Day" Report" at the beginning, the rest of the automation should be run using the "Day Report" code, not the "Night Report").
Is there a way to do one of the following
1. Label the input of "Day Report" or "Night Report" at the beginning of the automation (where the above except of code is how that would be done), and that can then be the determinant through the rest of the modules
2. Set my code in a specific module to, when it completes, automatically go to the same style of report (Day or Night) in the next module.
Can you run 2 modules at the same time on the same worksheet.
View 2 Replies View RelatedI have successfully rewritten all code in one workbook project. I have cut my Standard modules from 17 to just 4 modules.
Is there a way to remove all 17 modules at once so I can replace them with the 4 new ones?
I know that right clicking on the module and then click on "Remove...." will do it, but I would have to do that 17 times.
Not too bad if this was just one workbook to do. I have about 10 other books to do the same thing to. So that would be doing the right click 170 times.
I'm not even sure if this is possible. And if it is, I was thinking at probably having the code in a workbook open event to delete the Standard Modules??? Then I could just import the new modules.
If I put:
Sub t1()
Worksheets("sheet1").Cells(1, 1).Value = "abc"
End Sub
on sheet1, it works. But if I put it on module1, then it does not work. What do I miss here?
I created the following sub to signal when a macro in Module 1 is complete:
Public Sub Done()
Dim complete As Boolean
complete = True
End Sub
I placed this just before the end sub in the macro for which I am trying to detect that it has finished executing:
Call Done
End Sub
In the Sheet 1 Module, the code fails at the statement:
If complete = True Then
The error returned is "Variable not defined." All three subs are declared as Public. Why does the Sheet1 sub not recognize the variable "complete" from the Module 1 macro?
I want to set a variable for the range I want to copy so that the range can change between modules Sometimes I want to copy a1:x1 and Sometimes I want to copy a1:m1 what I did but it did not work
Dim myrange As range
myrange = a1:x1
range myrange.select
Selection.Copy
I would like to protect the VBA modules I have written in a spreadsheet. Is there any way of password protecting these (as there is with Excel workbooks/worksheets) -such that users can not see the VBA code unless they enter a password?
View 4 Replies View RelatedI have two different modules in my automation - to be specific one module to convert file from LH to RH and another module to do the reverse - convert RH to LH.
I have put up a radio button choice for the user and based on which radio button is selected would like to run that particular module.
Below is my code. It always throws an error "expected variable or function not module"
VB:
Option Explicit
Public Sub MAIN()
If ThisWorkbook.Worksheets("FRONT").OptionButton1.Value = True Then
Call LH_to_RH
[Code]....
I am following the correct procedure to call modules. A few minutes of search said the modules have to be public sub routines
When I try to open a worksheet that has any sort of macros I get the "error opening file" popup with the request to send the error to Microsoft.
When I check the box to "recover and save file" and proceed I am told that repairs were necessary to save the file
The repairs stated are " LOST VBA MODULES" and "LOST ACTIVEX CONTROLS"
I have not changed anything to my knowledge.
Changine the macro security settings to low has no effect either
I want the macro in this way. All sheets of the workbook. The name of the worksheet to a new workbook save as. But the modules do not get deleted.
View 1 Replies View RelatedI would like to know why some macro coding put in sheet and some put in modules?? What the different??
View 6 Replies View RelatedI have the following three codes repeated in five different User Forms,
Is there a way to put them all in one independent module?
I need to define a string in a specific workbook that can be called across any worksheet in that workbook.
The code in ThisWorkbook would be similar to:
Sub Workbook_Open()
MyID = "FCF"
End Sub
Within any Worksheet in ThisWorkbook...
Sub SomeMacro()
MsgBox = MyID
EnD Sub
The MsgBox should read FCF
I wrote some macros that allow me to check info when i input employee number and dates on a worksheet. There are three buttons in my macro which are "Prepare" (do some preparation for the origional data in order to perform check ups later on), "Clear" (clear info in order to perform next check up), "Check" ( Check the info that i need). I already finished the code for all three buttons and they are all functioning.
My question is how to create a userform that allows me to do the same thing as a macro. for example, on the userform window, there should also be three command buttons ("Prepare","Clear","Check") and also there should be three textbox labeled as "Employee Number","DateFrom","Date To" and the value of these textboxes are just the same as the input value for the macro( ie. In the macro, these three inputs are located at cells "B2","C2","D2")
Sometimes I will copy a macro to a different workbook and then modify it to do what I want instead of writing it new.
If it has a reference to a different macro, I have to go through each module in the "VBA Project" to fine it and see what it does.
I was wondering is there a way to fine a sub routine in a project without scrolling through each module to fine it? (without going back to the workbook and clicking on the view macro button)
Also is there a way to alphabetize each sub routine in a module so it can be found easier
I've started to group my subs better so I can find them easier, but there are a lot of old ones.
I just learned that I can name each module.