Using A Module Of Generic Functions In Other
Oct 15, 2008
I created a VBA module (Excel 2003) that contains many generic functions that I wrote. I want to use the functions from that modules in other Excel VBA projects (something like "Include" a library of functions).
View 2 Replies
ADVERTISEMENT
Mar 27, 2009
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?
View 2 Replies
View Related
Jan 24, 2013
Let's say i have 2 Modules on my VBA forms, is it possible to Copy all the Codes in Module 1 and Paste it to Module 2 by using a Command Button?
View 1 Replies
View Related
Jan 19, 2012
i got a question how i can make a msgbox in one module with 'Yes' linking to a different module.
such as: this is located in module2
Code:
If MsgBox("Do you want to activate module1?" & vbCr & _
"" _
, vbYesNo, "Choose") = vbNo Then Exit Sub
i want that vbYesNo different
No as in Exit Sub
yes as in activate Module1
View 5 Replies
View Related
Jun 9, 2013
I have an Excel worksheet used as an index for my holiday photo collection. The worksheet consists of a list of geographic locations visited for a particular holiday, and a hyperlink in each of those cells to the location of the corresponding photo on my hard drive ( eg C:NZ PhotosOtago\796.jpg). When I have taken some 10,000 photos on a trip, I find this an easy way to quickly view pictures of any site visited on the holiday.
The Excel index and the photos are stored in different partitions on my computer.
I now wish to share these photos by burning them to a DVD, but I would like the Excel photo index to be also on this disk, but with hyperlinks that refer to the photo files on the DVD, not the originals on my hard drive.
If this is possible, and the format of the hyperlink that I should use in future? e.g., instead of making the hyperlink E:NZ PhotosOtago\796.jpg, could I make it ..NZ PhotosOtago\796.jpg, so that I can transfer the Excel spreadsheet to a DVD with the photos?
Also, is there a way to do a global change of the hyperlinks in all the worksheet cells?
View 1 Replies
View Related
Feb 1, 2007
I'm trying to write a formatting macro that will insert a gray divider (row) into a blank line. I'm going to do this with a keyboard command, but I'm having a hard time selecting to column AJ. Obviously this command...
Range(Selection, Selection.End(xlToRight)).Select
...takes you to the end of the page, but I don't need to go that far, just to column AJ.
View 3 Replies
View Related
Aug 9, 2014
My final version will have more than 40 images with all the same code: they will all increment a corresponding SpinButton with 1.
[Code]....
View 13 Replies
View Related
Jan 1, 2009
how can i write the year and month in generic code for the following file path
.SaveAs Filename:= _
"S:RecsReportingRec StatsSummary Stats2009JanStat Summary_" & Format(Date, "dd-mm-yy") & ".xls"
View 9 Replies
View Related
Jan 20, 2010
The workbook has a tab for each day, and there are variance columns. The tabs are named for the date, like 1.20, 1.21, 1.22, etc.
For example, the formula on 1.21 in D2 is simply =C2-'1.20'!C2
That works fine, but it's a time-consuming job to always change it. You have one sheet to copy many times for all the other formulas, but then have to re-name and change that variance formula on each worksheet.
Is there a way to reference the prior worksheet without using it's specific name?
=C2-'prior worksheet'!C2 would be nice...I could take my one sheet and copy it about 23 times for each workday, then copy that whole workbook to use in the subsequent months without making any formula changes.
View 7 Replies
View Related
Aug 23, 2007
I am looking to create a macro that will edit the code of another macro that is already setup. Basically, I have a macro that will open and close every file that has data linked to this workbook. Because of the 255 character limitation of text in Excel, I have a simple macro to open/close each so it will bring over any additional characters past 255. Now, this macro is saved to a master file, and each month we do a save as, and start a new period on it. The files we open/close are named C:/data/RCC/FY2007/10543 - ifi/10543 CurrentMonth Rec.xls
Is there a way to make a macro, that will do a simple find -- replace in the VBA code of the original sheet, so that it looks for the right files. So, with the above example, I would replace "CurrentMonth" with whatever I enter into an inputbox (say AUG for August).
And if you have a moment, is there a way to make two input boxes, one to denote the Fiscal Year (in the file path it is the entry that is FY2007) and CurrentMonth, so that if it is the new fiscal month then it will create a new directory and save in that new location? So when it is FY 2008, I would do a save as C:/data/RCC/FY2008/10543 - ifi/10543 CurrentMonth Rec.xls?
View 5 Replies
View Related
Feb 15, 2008
Is there a way to generically sort all pivot rows of a pivot table alphabetically each time the table is refreshed? I have a pivot table that pulls its data from a dynamic named range on a separate worksheet. As users add data to the range and refresh the pivot table the newly added items appear at the bottom of the table rather than alphabetically. I know how to specifically call out a pivot row and have it sort alphabetically (see code below) but I still want to allow users the flexibility of changing the fields and order of the pivot rows so specifically calling out a pivot row by field name isn’t going to work. I need to somehow add code that says: For each pivot row (1 to n, where n = number of pivot rows) sort each in alphabetical order.
ActiveSheet.PivotTables("ptDWDM").PivotFields("Project Name").AutoSort _
xlAscending, "Project Name"
So in the above code I don’t want the reference to “Project Name” to be hard coded.
View 2 Replies
View Related
Oct 25, 2011
What i have at the moment is a module that contains code where i call a different module that i use as a procedure.
Module1
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?
Module3
Code:
MsgBox Cell
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
[Code]........
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?
View 5 Replies
View Related
Jan 23, 2009
I have recorded some script in excel to import a *.dat file, delete the first 19 rows of data, then export the data as a *.csv file.
My problem is I have circa 30 *.dat files to import, all of which have large file names and I am fed up with copying and pasting them in.
So my question is, in the below code, can I somehow use a reference at the start such as:
abc1.dat = "1"
abc2.dat = "2"
Then where the files were used, reference the "1".dat and its exported version "1".csv for the abc1.dat case.
View 10 Replies
View Related
Feb 25, 2014
My problem today, is actually being able to call the routines. I have tried to make a generic setup, so that each subroutine to be called is named "Macro_[number here]". So Macro_1, Macro_2 etc. By doing this I am hoping to be able to call all the subroutines using a For Each code.
At this point, my setup looks like this
Macro / Step
Action
Status
Run?
[Code]...
View 4 Replies
View Related
Aug 18, 2004
I recieve an error :
Run-time error '50289':
Can't perform operation since the project is protected.
When i try and run my code.
The code does add parts to modules and workbook events, but I need the code to be protected.
View 9 Replies
View Related
Mar 14, 2008
I am aware of the following topic in the VBA Help file:
"Using Microsoft Excel Worksheet Functions in Visual Basic
You can use most Microsoft Excel worksheet functions in your Visual Basic statements. To see a list of the worksheet functions you can use, see List of Worksheet Functions Available to Visual Basic.
Note Some worksheet functions aren’t useful in Visual Basic. For example, the Concatenate function isn’t needed because in Visual Basic you can use the & operator to join multiple text values."
And I'm aware of how to call Excel funcitons from within VBA; e.g., answer = Application.WorksheetFunction.Min(myRange)
However, not only are some Excel functions not useful; the fact is they cannot be used because VBA has a native function that does exactly the same thing and you have to use that native VBA function to achieve your goal. It is these overlapping functions that I am especially interested in. I want to know what I should use directly in VBA and what I need to go to Excel for.
View 9 Replies
View Related
Dec 21, 2012
I have created an Excel Add-in to create the Text file. I want to create the text file through select sheet from userform.
View 9 Replies
View Related
Jun 17, 2014
In my Personal Macro book, I have 2 modules, one for Functions and one for "macros".
Is there a point where it's more efficient to make a new module (or is the opposite true and it's more efficient if they are all in one)?
Does having a plethora of sub routines in a module slow down excel even though the routines are short? or would having them in different modules slow it down more?
View 4 Replies
View Related
Aug 24, 2008
I have been making and so i thought saving a module however every time i close the spreadsheet that module is associated with it deletes. is there any way to prevent this from happening.
Also when trying to edit on PERSONAL.XLSB!Module1 i get a particular error stating
"cannot edit a macro on a hidden workbook. Unhide the workbook using the Unhide command."
View 12 Replies
View Related
May 25, 2009
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.
View 2 Replies
View Related
Jun 9, 2009
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.
PROBLEM:
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: ....
View 13 Replies
View Related
Dec 1, 2009
I would like to have an email generated when a cell changes to a particular value. I've developed the macro to send the email with a saved attachment.
When I try to OJT-Engineer the text for the module, I can't get it to recognize the macro. It's a syntax issue, it seems.
What I need is for my module to initiate a macro when a cell changes to a value.
This is the code EXACTLY as it appears:
View 9 Replies
View Related
Jan 8, 2012
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
[code]....
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
Next varSheet
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"
View 1 Replies
View Related
Oct 10, 2007
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.
View 9 Replies
View Related
May 20, 2008
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?
View 9 Replies
View Related
Aug 6, 2008
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):
ActiveWorkbook.VBProject.VBComponents.Remove ActiveWorkbook.VBProject.VBComponents("Module1")
The fact that a module can delete itself blows my mind - but there are a couple of things I'm not sure about:
1. Presumably anything that's in my sub after the delete module line won't get executed?
2. If the saved-as workbook (Bvariant) is closed without saving, the module is still there when it is reopened. Is there a way to prevent this without putting new code into Bvariant?
View 9 Replies
View Related
Dec 17, 2008
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.
View 9 Replies
View Related
Sep 24, 2009
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?
View 9 Replies
View Related
Oct 15, 2009
I declared a constant like so:
Public Const iFirstRow As Integer = 6
I figured that any time I used this, at least in the same module, its value would be 6, but it was 0.
I changed it to ModuleName.iFirstRow, which seemed to set it straight.
Is this just how it is, or am I doing something wrong that is preventing me from using it without the module name?
View 9 Replies
View Related
Oct 24, 2009
I have been trying many different commands to run a module from a userform, but nothing is working. I'm sure it's possible, right?
Basically, I'm trying to run modules based on a selection made via a listbox.
View 9 Replies
View Related