Closing Workbook After Calling External Module

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


ADVERTISEMENT

Calling Named Range From External Workbook

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

Copy Module To External Workbook

Mar 26, 2009

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....

View 9 Replies View Related

Calling Module In Module With Variables

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

Closing Workbook When Closing Userform

Sep 14, 2006

I have a userform which opens when the workbook opens. Ideally Id like to have the userform open without the workbook coming up and have the workbook close when you close the userform. If thats not doable then is there a way to just close the workbook when the userform is closed?

View 3 Replies View Related

Macro Is Closing Wrong Workbook Before Going To The Next Workbook

Aug 12, 2009

I run most of my macros out of a file called "Personal.XLS" and I have this bit of code at the end of this particular macro which is closing personal.xls instead of the active file it is working on. It is set up on a loop and it should go to the next file in the directory but since it closes the file I run the macro from, the macro stops immediately. It appears that it believes "ThisWorkbook.Close" is referring to the file from which the macro is initiated.

View 2 Replies View Related

Calling Form From Another Workbook

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

Calling Macro From Different Workbook

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

Calling Macro's From Another Workbook

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

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 View Related

Calling Subs When Workbook Opens

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

Closing Workbook At The End

Aug 22, 2012

I have a perfectly functioning piece of code. There is still one snag, however. In the process of running the macro, three new workbooks are opened. I would like to close all three of those workbooks at the end. I am using the following procedure for each of the sheets:

To open the worksheet

Code:
Dim wb As WorkbookMsgBox "Please select the Stakeholder File"SHFile = Application.GetOpenFilename("Files (*.xls),*.xls", , "Please select the Stakeholder Workbook")If SHFile "False" Then Set wb = Workbooks.Open(Filename:=SHFile)

To close the worksheet at the end:

Code:
If Not wb is Nothing Then wb.Close SaveChanges:=False

The only problem is that I am getting bugs when closing multiple workbooks (3). I have assigned the names wb, vb and ab to the three workbooks.

View 5 Replies View Related

Before Closing The Workbook

Apr 19, 2006

I have some VBA code which opens another workbook, copies data from the first sheet in there and pastes into the current sheet before closing the workbook it got the data from. Is there any way of suppressing any messages associated with closing the other workbook? i.e. do you want to save - or possibly automatically generating a no message to the prompts?

View 3 Replies View Related

Closing Workbook With VBA Without SAVING?

Nov 27, 2012

I'm trying to close a workbook without saving it. But everytime I get the message box popupped twice.

These are the codes that I use:

VB:
Private Sub Workbook_BeforeClose _(Cancel As Boolean)
Dim YesOrNoAnswerToMessageBox As String
Dim QuestionToMessageBox As String

[Code].....

View 4 Replies View Related

Reminder When Closing A Workbook

Jan 11, 2007

I have 4 employees who at the end of their shifts have to email me an excel workbook. The issue is that some of them are forgetful and after placing numerous post-it notes on their monitors one particular employees just forgets.

What i want to do if possible is that when the workbook gets closed, a pop-up window shows up on their screen reminding them to send the workbook. Even better would be if their was a button that they could click that would email the workbook as an attachment in the pop-up box.

View 11 Replies View Related

Closing A Workbook Created?

Mar 25, 2014

I've created a macro which copies the current tab to a new workbook (Book X):

[Code]....

I then manipulate the copied data in Book X. Once this is done I move the manipulated sheet back into original file

[Code] .......

The problem i'm having is I'd like to close the newly created Workbook X file once the macro has run but Workbook X is usually called Book2, Book4, Book7, Book32 etc.

Workbook X will always be the previous file if i use the ALT TAB shortcut.

View 2 Replies View Related

Pop-up Message Appear When Closing Workbook

Dec 6, 2007

Is it possible to pop up a message when closing the workbook?

if so, could the message only popup if a certain cell is negative?

For example, This is what i would like to happen.

When workbook close is activated:
If cell A1=(-20), then pop-up "Please check your work and correct".

else, close workbook

View 14 Replies View Related

Closing Workbook & Excel

Jun 26, 2009

How do I SAVE and CLOSE Workbook and it's instance of Excel.

I have other instances of excel open that I do not want closed.

I thought that I had this before, but I can't find it if I did. I do keep a list of all the requests where I ask for help and it's not in this list.

View 6 Replies View Related

From Userform / Other Workbook Not Closing

Nov 26, 2013

I wrote this macro where, from a userform, I click a button and it will fillout another form with certain data from the original WB to a different WB.

All is working fine and exactly the way I want it except, it won't close and save the other sheet. It will go back to the userform, as I want it to, but it will leave the other file in the background open.

This is the code:

Code:
Private Sub CommandButton6_Click()
'Allocation file fill out
Dim alloc As String
Dim allwb As Workbook
Dim ABA As Workbook
Dim Prompt As String
'Dim fd As FileDialog
Set ABA = ThisWorkbook

[code]....

View 2 Replies View Related

Closing A Workbook That Is Open Via VBA

Jul 2, 2008

Well I seem to be having an issue in a form i created. What happens is that when the user clicks a button it saves a worksheet of workbook as its own file, problem is that it will actually open the new worksheet as a workbook when I really just want it to save without opening a new instance. Here is the code

Dim IntWirefilename As String
Worksheets("Intwires").Select
Worksheets("Intwires").Copy
IntWirefilename = "International Wires Database"
Worksheets("Intwires").SaveAs FileName:="File Path" & IntWirefilename & (".xls")
Workbooks("File PathInternational Wires Database.xls").Close
I think the problem lies in the last line or it could be from the select and copy part.

I do not want it to open a new file after it saves it. Also can anyone help create a part that will bypass the overwrite existing file thing so that this file will just continuously save as the same file name rather than prompting the user constantly to Overwrite the file.

View 9 Replies View Related

Prevent Closing Of Workbook By Top Right X

Nov 20, 2007

I need to alter the Close command on the title bar (the 'X' on the top right corner on the blue bar of excel)

Is there any way to alter the close button on the title bar to have it call a sub I created instead of actually closing excel?

View 6 Replies View Related

Calling Macro In Another Workbook And Carrying Some Variables Back And Forth

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

Closing The Workbook & Saving Automatically

Jan 25, 2008

I have my Excel workbook open & have made changes. Now I close it and Excel prompts me if I want to save the changes. Is there a way to just close the workbook and automatically accept any changes without have the "Do you want to save changes" message appear?

What about if it is opened in read-only mode? Typically the workbook will not save any changes unless you save it off as another file name. If there is a solution to my question above, can it be enabled only when the workbook is opened in edit mode, or will it not auto-save changes over the file because Excel knows it was opened in read-only mode?

View 9 Replies View Related

Closing A Workbook Without Saving - Macro

Nov 28, 2008

Need the VBA code to close a workbook, and not save it? I need it to open a workbook, run a macro, and close without saving. The code I have thus far is:

View 3 Replies View Related

Prevent Closing Of One Workbook When Two Are Open

Sep 23, 2009

I'm trying to prevent a user from closing a perticular workbook.

Here is some important factors.

Workbook(A) = "LA-01-04-10" This is only one of 52 other but only one is open at a time.

Workbook(B) = "LA.xls" Always the same name and is always opened when one of the workbooks(A) above it opened.


When workbook (A) is opened it will then open another workbook (B) at that time the window is hidden workbook(B) So the user can only see workbook (A) I have a button on workbook(A) that unhides the window to show workbook(B) After the user completes his work in Workbook (B) they need to click another button that sorts the list and returns them to workbook(A) (Which also hides the window for workbook(B).

The problem is I have users that are trying to close workbook(B) instead of pressing the sort list button. So what I want is to prevent the user from closing workbook(B) by displaying a msgbox saying they need to press the button.

Ive tried several approches to this but I'm still having problems. The below script works if workbook(B) is active or shown. The message is displayed and the workbook will not close. However if the user is in workbook (A) and trys to close the message is displayed and both workbooks close like they are suppose to. But why is the message displayed?

One other note I should say is that not only does workbook(A)Open workbook (B) but it also closes it. Which may be why I'm having problems?

I have also included both workbooks so you can see all the code.

I have this code in Thisworkbook of workbook(B)

View 10 Replies View Related

Before Close Not Working On Closing Workbook

Sep 29, 2009

I am hoping someone can help. I am new to writing macros and have the following in the this workbook page. When opening the macro does exactly what I want and expect, but does not do the "before close" part. If I select the macro in editor and run it, it does just what I want, so dont understand what is going wrong. Do I have to put in some kind of prompt, or manually run this before close - preferably I would like it to just run.

secondly, I have password protected the workbook, but have to put the password in the macro, is there any way of making this invisible to anyone who then reads the macro....

View 9 Replies View Related

Workbook Automatically Opens After Closing

Jan 6, 2010

I have a workbook on a share drive that is used by multiple people. In the event that someone leaves the workbook open after using it, I have a timer function that pops up a splash screen after 4 minutes of inactivity which states, "This workbook will close in 1 minute if there is no further activity". If there is no further activity in that minute, the workbook closes.

The code works fine...unless the workbook is manually closed in that minute between the splash screen and when the timer would have closed the workbook. If that happens, the workbook closes normally and then briefly reopens and closes a minute later when the timer would have closed the workbook. Is there any code to prevent this?

View 4 Replies View Related

Macro Commands When Closing Workbook

Dec 13, 2011

Is there a way (with macros, I''m assuming), to make my workbook always return to the Main tab and Save automatically --- every time somebody closes the workbook from any tab - so that the next person who opens the workbook will have it ready to go on the main tab?

View 5 Replies View Related

Script Works But Not After Closing Out Of The Workbook

Feb 26, 2009

I have a workbook setup with 4 sheets that I'm using. I need the 4 sheets to type in all caps when I enter the data. I found a script, and followed the directions. It works great, yet when I close out of the workbook, and open it back up, the script doesn't work anymore. I go to check the 'view code', and it still there. I resave it, and try it again, and it still doesn't work, what am I missing? This is all new to me. I am saving it as a Workbook Macro enabled file type.

Once I get this resolved, is there a way to make it default to use the script everytime I open the workbook?

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count > 1 Or Target.HasFormula Then Exit Sub
On Error Resume Next
If Not Intersect(Target, Range("B3:O210")) Is Nothing Then
Application.EnableEvents = False
Target = UCase(Target)
Application.EnableEvents = True
End If
On Error GoTo 0
End Sub

View 9 Replies View Related

Closing Workbook Runs BeforeClose VBA Twice

Sep 11, 2009

In the various codes I am using AutoOpen, AutoClose, Workbook_BeforeClose and Workbook_BeforeSave Subs. BeforeClose and BeforeSave are in '_ThisWorkbook'; AutoOpen and AutoClose are in a Module. I also use Workbook_Open, Workbook_Activate and Workbook_Deactivate, also in _ThisWorkbook. I put message boxes thru out code to be sure code was running right. The Workbook_BeforeClose is running twice under certain condition (when a cell in active workbook sheet is blank ("")). I do not understand why it is running twice.

For condition where there is data in cell M10, this creates a whole other issue ( multiple running of mutliple various Subs) which I believe I should deal with in different thread/question.

Private Sub Workbook_BeforeClose(Cancel As Boolean)

Worksheets("PanelSched").Activate
MsgBox "Test-Before close"
If Range("M10") <> "" Then
Dim PanelName As String
PanelName = Range("M10").Text

View 9 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved