Calling A Procedure From A Different Workbook
Sep 1, 2004
I have designed a multipage userform which is executed through a toolbar button in my Excel. How can I access this Userform from another workbook with a different file name?
I have tried by using the tool>References and checking the VBAProject in the original workbook, however, when I click on the toolbar button in Excel (to activate the userform dialog box), the error message "A document with the filename already exists. Cannot open two documents with same name." Problem is....the filenames are not the same.
View 5 Replies
ADVERTISEMENT
Feb 2, 2010
I need to extract the filename “My Excel File” from Worksheets(“Sheet1”).Range(“A1”), whose value = C:Documents and Settingsuser1DesktopMy Excel File
I found on Chip Pearson’s site a Function TrimToChar which, using SearchFromRight and a TrimChar of “” will trim OFF the filename “My Excel File”, leaving the Path.
But, I think I could use his function to tell me the number of characters in the Path and then use that to extract the remaining characters from the total character length (Mid Function)
Problem is, I don’t have a clue how to call a Function in VBA to work on Worksheets(“Sheet1”).Range(“A1”). How do you set the InputText , TrimChar, & SearchFromRight?????
(eventually, this will be in a loop, where I extract the filename from a Dynamic Named Range (list) in Column A)
View 3 Replies
View Related
May 31, 2007
I have a procedure(try) which call two other procedures ( try1(),try2())
try1 - ask for a range of First cell
try2 - ask for a range of Last cell
Now issue comes when user pressess cancel button for try1() it Exits try1() and goes back to try() and calls try2() but i want that if user pressess cancel it must also exit from try() too (calling function)
Sub try()
try1
try2
End Sub
Sub try1()
View 9 Replies
View Related
Apr 27, 2007
Is it possible to call a stored proc from excel and pass through a paramter?
If it is would anyone have a clue how to do this?
View 11 Replies
View Related
Mar 5, 2013
I have a hundred or more spreadsheets that I will be applying a utility to. I want to use one button on each sheet to call a form in the utility workbook. That form will have buttons that call individual parts of the utility.
I tried application.run("utility.xlsm!frmStart"). No dice.
I also tried: "utility.xlsm!frmStart". Same result.
How can I overcome this.
The reason I want my forms in a different workbook is the difficulty with maintenance and installation.
View 2 Replies
View Related
Nov 14, 2006
I have a set of eight files, each of which is refreshed daily through a macro. I wanted to set up a master macro in a separate file that would open up each of the eight in turn, calls its refresh macro (which saves and closes the workbook), and then open up the next one, etc. I've searched the board and Help on this subject, but I keep getting an error:
Sub UpdateCSHoldReports()
' A sub to update all the US CS Hold Reports
' First, change the directory to the one that holds the files
ChDir "s:Marketing_ReportsCustomer Service2006CS Hold ReportsUSA"
' Next, open each file in turn, and run its refresh macro
' The refresh macro saves and closes the file automatically
Workbooks.Open ("VERIFICATION HOLDS 1000 PLUS.xls")
Workbooks("VERIFICATION HOLDS 1000 PLUS.xls").Activate
ActiveWorkbook.Sheets(1).Activate
Application.Run ("VERIFICATION HOLDS 1000 PLUS.xls!V1000Refresh")
End Sub
I'm only working on one file right now; I'll add the others when I get this one going. The error message I get is "1004" "The macro VERIFICATION HOLDS 1000 PLUS.xls!V1000Refresh cannot be found." It occurs when the Application.Run statement attempts to execute.
What obvious thing am I missing here? I have checked all the spellings, etc., so it's not something like that.
View 9 Replies
View Related
Nov 26, 2009
I have been combining multiple macro's into one large Macro and after research, it seems that only the call function works without any hitches.
Is there a way to use the call feature in one workbook while the macro's themselves, 5 or 6 of them, are in another workbook that is closed?
All users would have access to both workbooks.
The reason I am trying this is because I do not want all the other users to have to choose between multiple macro's and some of my colleagues like to use a radio button to link to the workbook. so it needs to have one file in it...
View 9 Replies
View Related
Mar 7, 2012
I have the following code in a module that I would like to initiate when the workbook opens:
Code:
Private Declare Function GetComputerName Lib "kernel32" _
Alias "GetComputerNameA" ( _
ByVal lpBuffer As String, _
ByRef nSize As Long) As Long
Public Property Get ComputerName() As String
[Code] ........
In a worksheet, I have =compname() in cell A1 and =hdserialnumber() in A2. What is the trick to make the values in these cells appear as soon as the worksheet opens?
View 2 Replies
View Related
Jun 12, 2009
I want to copy a named range from an external workbook. Currently I am using some VBA copied from a recorded macro that first opend the 2nd workbook and then selects the named range, changes back to the original workbook and drops the copied range into the active workbook.
I would like to find a way to get around having to open the reference workbook, and instead simply point to the proper workbook name and named range.
View 3 Replies
View Related
May 6, 2007
I have a workbook (Program_1.xls) which references another workbook (Program_2.xls). I want to close Program_1.xls using code in Program_2.xls.
When the Program_1.xls is closed, the code stops.
Program_1.xls code
Sub Program_1()
MsgBox "This is program #1"
Application.Run "Program2.xls!Program_2"
End Sub
Program_2.xls code
Sub Program_2()
Source = "C:Documents and SettingsCohenMy Documentsprogram3.xls"
target = "C:Documents and SettingsCohenMy Documentsprogram1.xls"
Workbooks("Program1.xls").Close savechanges:=False
' ---> code halts here
MsgBox "This is program #2"
FileCopy Source, target
End Sub
How do I get the final 2 lines of code to execute?
View 9 Replies
View Related
Feb 28, 2006
When i open the MS-excell and i go to see the VBeditor i can see the following in the project window:
- spacereport(space.xla)
-microsoft excel objects
sheet1
[Code].....
All the code in spacereport project, let me go to File-->Space and then run a report previously added. what i would like to do is, being in the book3 project, execute modules and forms from spacereport project.
View 6 Replies
View Related
May 22, 2013
I have a macro running in a workbook that gathers some data (a date, a string and a few arrays). Towards the end of this macro, I need it to open another workbook and run a macro that sits in this other workbook, using the data from the first workbook. I then need it to return some results (several integers) back to the first macro to be pasted into the first workbook.
I gather that I can't use 'Call' as the second macro is in another workbook.
I've found that I can use Application.Run but I'm unsure how to carry variables back and forth using this.
How to move the variables between macros / workbooks using the Application.Run option, or maybe another way of doing things?
View 1 Replies
View Related
Aug 22, 2014
I have a procedure that opens workbooks from a list and then searchs for a phrase given by user. If nothing is found it closes workbook and opens next one. If phrase is found it highlights it on workbook. I wanted to give user some options when phrase is found: to search further in next workbook and to search further, but leaving current workbook open. Here my misery starts.
The only way i made up to perform it was to use Userform and code: userform.ActiveControl.Name. But it seems that Userform called in other workbook than one where the module is, interrupts somehow the procedure. When workbook, where the userform was used, closes the procedure doesn't go on. Evidently Userform is the issue here as without it, macro works.
See my code below :
[Code] .........
View 8 Replies
View Related
Oct 22, 2007
i have 5040 rows in a sheet. in columns A,B,C,D,E,F, i have some input. and based on that i have some formula on column G.
lets say, min value is at row 4094 by looking at G column... i want to call entire row to the, lets say K L M N O P ....i need a formula for that....
random numbers are included in the formula. So ever time i make any changes on the sheet, min value changes even thought i dont play with the formula and input... so i want my new min value shown at row 1 of K L M N O P, every time i do that
how can i do that?
View 11 Replies
View Related
Sep 26, 2009
I am creating a set of lists, each on a different sheet. I want to have the first sheet as a sort of "Title Page" with basic information from the others. Is it possible to create a link of some types so that I could click on "Magazines" for example and go to the sheet called Magazines, or "Books" and go to the sheet called books. The latter would be very handy as this workbook has around 30 sheets in it, which is a pain to look through to find the right one.
View 2 Replies
View Related
Feb 12, 2009
I have created an XLA using a blank workbook which has a macro (called CompareMan) I have written within it.
I have written a utility (called INSTALLMAN) to install this add in.
When I run the install it creates and activates the add in OK.
The install also creates a toolbar with a button to trigger the macro.
Problem is, when I click the newly created button, no matter which workbook I am currently in I get a message ...
"The macro INSTALLMAN.xls!CompareMan cannot be found".
So my question is, how do I get my button to trigger the macro in my add in?
View 14 Replies
View Related
Apr 15, 2009
I have to do the same procedure for a number of profit centers. The only differences are the names of these profit centers. Therefore I want to use the same code, with changing references. How can I use this array so that it calls/uses 1 profit center at the time? If I use the following code they all are used at once (P1100P1200P1300P1500P1600P1900)
View 2 Replies
View Related
Jun 22, 2009
Is there a way to call a sub with out actually saying its name? In other words can I refer to a sub by a value or a cell that holds its name? for example, in my CNC programs I often use something like this;
View 14 Replies
View Related
Jan 20, 2012
Okay, I know you can reference worksheet functions with code like:
application.search()
But how do you use a UDF function within VBA???
I tried, thisworkbook.UDF() (UDF being the name of any UDF) but it didn't work.
View 3 Replies
View Related
Mar 13, 2012
I have a add in for excel (self made) and I recently hit a wall when trying to add functionality to it.
I have a form "UserForm1" created within the .Xlam file of the add in.
I want this form to be useable for any excel file that might be open, so putting code in the excel file that needs to use the form is undesirable.
The functions carried out by my add in are activated trough ribbon buttons.
my goal is to have a button on the ribbon that loads the form.
As the UserForm1.show code doesn't work, I will need a alternative.
I did find the code for making the sheet show if there would be a button in the workbook, however I want all code to be in the add in.
View 4 Replies
View Related
Mar 17, 2012
I am using the following code to find the text "Employment" in any row in colum H. If found it copies it to another worksheet.
Sub CopyRowsSht8()Sheet8.SelectSet Rng = Sheet8.Range(Sheet8.Range("H1"), Sheet8.Range("H" & Rows.Count).End(xlUp))For Each cell In RngIf cell.Value = "Employment" Thennum = cell.RowSheet8.Range("A" & num & ":" & "L" & num).Copy Destination:=Worksheets("Employment").Range("A" & Rows.Count).End(xlUp).Offset(1, 0)End IfNextCall CopyRowsSht9End Sub
1. This sub calls CopyRowsSht8 and then this calls CopyRowsSht9 and so on. I have 15 sheets so how would I code this into some kind of loop to include sheets 8 to 22 instead of calling sub then sub then sub etc.
2. It takes a while to do just two sheets so 15 would be very slow - can this be made faster. The maximun number of rows containing data is only about 100 on each sheet -could that make a difference?
View 1 Replies
View Related
Mar 14, 2008
Im trying to call another subroutine within the same workbook but it doesnt work,
---------------------
Sub Macro1()
Dim mac1 As Variant
Dim mysub As Variant
Select Case Cells(1, 3)
Case mac1
Call mysub
End Select
End Sub
---------------------
View 9 Replies
View Related
Apr 14, 2009
The below thing has been driving me up a wall for 2 days now. I know the fix has to do with calling the variables, but I can't figure out the exact code.
Sub Parsing_Logic()
Dim IBG_URL As String
Dim A As String
A = Mid(IBG_URL, Application.WorksheetFunction.Find("/200", IBGURL), 8)
Dim B As String
B = Left(IBG_URL, Application.WorksheetFunction.Find("/200", IBGURL))
Dim C As String
C = Right(IBG_URL, Len(IBG_URL) - (Len(A) + Len(B)))
Dim D As String
D = Left(C, Application.WorksheetFunction.Find(".200", C))
End Sub
Function IBGLink(IBG_URL As String, Formatted_Date As String)
If Application.WorksheetFunction.IsErr(A) Then
IBGLink = (D & Formatted_Date)
Else: IBGLink = (B & Formatted_Date & D & Formatted_Date)
End If
View 9 Replies
View Related
Aug 4, 2006
I am trying to call another macro, but instead of using the name of the macro, I have it in a variable. I am getting an error that says "Compile Error: Expected sub, Function, or Property." Can you call a macro that is in a variable? I basically have a bunch of macros created. I also have a list of the name of those macros on a worksheet in Excel. I want excel to start at the top of the list in excel and run the macro, then move down and run the next macro, and so on. Below is my code.
Sub Commercial_2005()
Dim Macroname As String
Workbooks("bleeg.xls").Activate
Worksheets("CommercialList").Select
Cells.Range("a1").Select
While ActiveCell.Value <> ""
Macroname = ActiveCell.Value
Workbooks("copy of recast_Report_v2.xls").Activate
Call Macroname
Workbooks("bleeg.xls").Activate
Worksheets("CommercialList").Select
ActiveCell.Offset(1, 0).Select
Wend
End Sub
View 3 Replies
View Related
May 1, 2007
I guess I just don't understand the basics of calling a function. I have the following function in a standard module:
Function CleanUp(ws As Worksheets)
ws. Range("A2:P100").ClearContents
End Function
I have this code in a worksheet module:
Sub Trying_to_call_a_function()
CleanUp (ThisWorkbook.Worksheets("Month End"))
End Sub
But when I run the routine that calls the "CleanUp" function, I get the message: "Object doesn't support this property or method." I have tried changing the Function to this: CleanUp (ws as Worksheet) [instead of (ws as WorksheetS)]. Yet, this does not change anything.
View 3 Replies
View Related
May 23, 2007
Is calling a subroutine within another different than running it from the play button in the VB editor? I am getting different results.
I have the following code that I want to call from another subroutine that creates a series of command buttons.
Sub DynamicButtons()
Dim ButtonCount As Integer
Dim ctl As OLEObject
' Create the Button objects
ButtonCount = 0
For Each ctl In Sheets("Sheet1").OLEObjects .............
View 9 Replies
View Related
Nov 4, 2008
I'm not sure whether this should be a general question or it should go in the programming section... but here here goes anyways
I need to create a spreadsheet where the contents of Col A & B in Sheet1 are copied into both Col A & B in Sheet2 & Sheet3. Sheet1 Col A&B will be continuously updated (rows will be added) and as these columns are updated, Col A & B in Sheet2 & Sheet3 should be updated automatically and keep the format that is set in Col A & B in Sheet1.
Now, Col C&D in Sheet2 & 3 will be updated by a different user. As the user updates the cells in Col C&D in Sheet2 & 3, Col C&D in Sheet1 should automatically be updated with the data in the cells of Col C&D in Sheet2 (and keep the format) and Col E&F in Sheet1 should automatically be updated with the data in the cells of Col C&D in Sheet3 (and keep the format).
View 12 Replies
View Related
Oct 28, 2009
Currently I'm trying to set up a table that referneces sheets that don't yet exist. These sheets will be added by the user or by macro, either one. I want my table to automatically take these pages into account when they're created without having to rewrite my formulas. The problem is that when I make the call to a sheet that's not there, it opens a file open dialogue box and I don't want it to do that. Is there something I can do here about that?
I don't think it's really going to shed any light on the subject, but this is my call (from memory, not copy and paste)
IF(OR(ISERROR('P01'!N2),'P01'!N2 = ""),"",'P01'!N2)
Also, when I enter this formula and the sheet doesn't exist, it automatically reverts to a text field and I have to manually switch it back to general in which case it gives a #REF error (which is just fine).
Also, I'm writing it in Excel 2003, but it completely crashes Excel '97 if I try to open it there, how can I fix this?
View 6 Replies
View Related
Feb 4, 2014
I've got three workbooks that end users will be using for data entry. The VBA code for the three workbooks is identical.
I'm trying to encapsulate the code into an add-in so I only have one copy of the code that I have to debug/maintain.
Furthermore, I've also encapsulated the code in the add-in into a class. The class isn't really a "usual" object modelling some data; rather, it's a utility class processing Worksheet_Change and Worksheet_Activate events. Hopefully this isn't a really bad idea, rather than keeping the code in standard modules in the add-in.
The application is called "Midas". Here are some code excerpts:
Midas.xlam:
Standard Module:
[Code] ......
Class Module:
[Code] .....
And in the end user workbook:
[Code] .....
The Wbk_SheetChange event handler is triggering, but it's looking for the code in the end user workbook, instead of the class. Is there a way I can change
[Code] .....
to call the private routine "Cases_Changed" (where "Cases" is the sheetname) residing in the class instead of looking for it in the workbook?
View 4 Replies
View Related
Aug 13, 2007
Hi, i'm having a terrible problem (at least for me).
I want to use a var from a UserForm to use it in calculation method in a Module.
How can i refer to that variable in the Userform in the Module code?
View 11 Replies
View Related