After all the awesome macros I've obtained with the help of all of you, I now have over 30 macros, each in its own module. I have tried without success to re-name the modules with no luck. How is everyone organizing these?
What i have at the moment is a module that contains code where i call a different module that i use as a procedure.
Code: If Sheet1.Range("C4").Value < Sheet1.Range("A2").Value Then If Sheet1.Range("K4") = "" Then MsgBox "Please check 06:00 tasks not done yet!" Cell = "Range(" & Chr(34) & "F4" & Chr(34) & ")" If Sheet1.Range("C4") + 0.042 < Sheet1.Range("A2") Then Run "EmailProSheet" End If End If End If
EmailProSheet is what i call but now i want to use the variable "Cell" in the procedure as well?
Code: MsgBox Cell Set OutApp = CreateObject("Outlook.Application") Set OutMail = OutApp.CreateItem(0) On Error Resume Next
As it is now everything is working fine but does not return a value in "Cell" if the procedure is called. Is there another way?
Want to Copy a Module(s) to another workbook in a different path and also password protect it at the same time using VBA.
I need to copy some Module(s) from One WorkBook to another using VBA..
I have used the following code to good effect, however my TargetWb is not at the same path, so I need some modification in this code if that's possible and also this VBA Module which is Copied and Pasted in the Target WOrkbook needs to be Password Protected so that it cannot be tampered.
The code which I'm using currently is:
Sub CopyModule(SourceWB As Workbook, strModuleName As String, _ TargetWB As Workbook) ' copies a module from one workbook to another ' example: ' CopyModule Workbooks("Book1.xls"), "Module1", _
Sub Try() Call CopyModule(Activeworkbook, "Module1", TargetWb)
on this to pass the TargetWb as a variable which can be generated in the code used for generating the File using a Macro..
In the above code The SourceWB would be the ActiveWorkbook and the Target Workbook is the file created using another Macro from several sheets of the Active Workbook and its created in a folder with a specific name and therefore the Path is one more level inside than the Active Workbook.
if the Transferred Module can be Passworrd Protected and Locked for editing..for the end user.
I have been trying for some days to copy a module to an external workbook with VBA. I have about 40 workbooks that have the same format. although I developed these sheets. I am not the person who uses them. I have to on occasion alter the code for some reason, its getting tiresome.
I don't think I can use the personal workbook method for this as it is not me using the workbooks. I don't even know some of the people that use them. This courses me problems because of the number of workbooks. I want to be able to maintain the code by having to write it once and propagate it through the necessary files via the VBA.
I have code from C Pearson that copies a module to another workbook.
I have posted this here just in case. Most threads on this subject just direct you here any way....
I am trying to create a new sheet from an existing sheet. I only need to copy the sheets and not the code from the original sheet. But, when I copy the first sheet the code module also gets copied to this new sheet.
I inserted a second module into a project. Now I want to delete it. Only i can't figure out how to do this. I highlite it and right click or click edit from the toolbar but i'm provided no options. I can't drag it to the trash either.
I have a Form that when the 'SUBMIT' button is clicked, I would like to validate the information and then write it to a 'MASTER SHEET'. However, the validation has gotten lengthy and I have opted to put the validation code in a separate Module to keep my general code a little cleaner.
The original code would kick you back to the form if something was wrong via a 'END SUB', but as now the SUB is on a different Module, it isn't working.
Here is the pertinent code on the general code sheet: ....
I have 3 modules that all use the same Excel Workbooks, but just perform different actions in each module. It's such a waste of space! I was wondering if there was a way that I could combine all 3 modules into one module.
For example Module 1 is:
Code: Dim Varbooks Dim varBook Dim wb as Excel.Workbook Varbooks = Array("Fire", "Ice", "Alpha") For Each varbook in Varbooks 'Run the below code Next Varbook
Module 2 reads:
Code: 'declare all variables CurrentPath = ActiveWorkbook.Path varBook = Array (same varbooks as above) 'Run different code Next varbook
Varsheets (I use varsheets instead of varbooks this time only difference, but they are sheets inside a masterworkbook, as opposed to being workbooks themselves, but exactly the same names)
'Run a totaly different code here
Is it possible to somehow combine all 3 of those into one module? I have tried, but I keep getting a compile error of "For Control Variable Already in Use"
I have code broken out between two different modules due to size limitations in a single module. I'm not able to figure out how to move to the second module after running the first module. I've tried something like this:
Sub FirstModule() 'Code 'Code 'Code SecondModule End Sub
Sub SecondModule() 'Code 'Code 'Code End Sub
I'm getting an error that says "Compile error: Expected variable or procedure, not module". I understand that it's not allowing me to use the name of a module as a procedure, but I can't find any information on how to call the second module.
I defined function ConcatenateIf() in Module 1, that would take a range and combine the cell contents:
Function ConcatenateIf(iRange As Range, iLook As String, iNum As Integer) For Each cell In iRange If cell.Value iLook Then ConcatenateIf = ConcatenateIf & Chr$(10) & cell.Offset(0, iNum).Value End If Next cell End Function
Works beautifully. Then I save, and close. When I re-open, all the cells that reference this function display #NAME? error, like it can't find the ConcatenateIf() function. Does this have something to do with macro security? If so, why would it work at first, and then stop working?
I've got some code in workbook A that reformats another workbook B. Basically, it moves all the sheets across to A, creates a pivot table and chart, then saves itself as a variant of the original filename B. The last things it does is to delete the one sheet that was originally in A, and then delete the module that the code is running from (using some code from Chip Pearson):
i am going to ask is for my curiosity only and to be sure that no one will break my password. If the VBA module is locked for viewing and password protected, it can't be cracked??I asking this, because i made an excel application with macros, and i don't want the user of it to crack my password. I have to mention that the password is 17 letter+spaces long. I repeat again....i asked this ONLY for my application safety.
This module consists of app. 25 sub routines. Every sub routine is a For-Next Loop, with 70 For-Nexts to work through. The loops check certain input cells and if these cells are empty, the row is hidden. I have the reverse also where I can unhide these rows.
When I had about 8 of these loops in this module, it would work quite fast and it took about a second to run one of these subs. Now that I have 25 if I run one of these subs it takes about 20-30 seconds.
Before I break them all down into individual modules just to find out it doesn't work, is there anything else I should be doing or could try to speed these subs up? If breaking them down into more than one module is the solution, how do I do this best?
I would like to create a class module that it's the same as a connector shape (for example), but with additional custom properties defined by me. For example, I would like it to have a temperature property.
So, for example if I write in a Sub procedure:
Dim Test1 as EnhancedConnector Set Test1 = New EnhancedConnector A new connector appears in the activesheet, but this connector must have my custom defined properties available to VBA Code
I have an existing module that queries a SQL database and populates a worksheet using VBA. I would like to add to this module to include a sum of columns, but as this sheet is always dynamic, i am not sure how to sum this appropriately. for example, I have column B, I would like to add the rows from a certain point in the worksheet, but this is always dynamic, is there a way to accomodate for this so that I am always summing the column in the correct place?