ThisWorkbook.Close question

Please take a look at the code below:

Public Sub DumbFoo ( )
    ThisWorkbook.Close()

    Sheet1.Range("A1").Value = -1
    ThisWorkbook.Save()
End Sub


Is it safe to assume that the code below the
"ThisWorkbook.Close()" line will NOT be
executed???    My question is basically:  Does
all VBA code stop executing once a .Close()
function is called???

Thank you!


0
Robert
1/24/2010 2:30:09 AM
excel.programming 6508 articles. 2 followers. Follow

2 Replies
1322 Views

Similar Articles

[PageSpeed] 52

I don't believe the code would execute at all because of the parentheses 
after Close.  It would throw an error an tell you that something is missing, 
or type mismatch.  But, if you did have the correct syntax, without the 
parentheses, then the workbook would close and no further sheet activity 
would be processed and the workbook would not be saved, but you would 
probably get a message asking you if you want to save the workbook.

Be careful where you put the parentheses in VBA.  They usually indicate that 
something is needed to complete the command or modify the object.  If that 
something is not included in the parentheses it throws an error.

See "Using Parentheses in Code" in the VBA help files for more details.


"Robert Crandal" <nobody@gmail.com> wrote in message 
news:QgO6n.14679$PI7.6161@newsfe17.iad...
> Please take a look at the code below:
>
> Public Sub DumbFoo ( )
>    ThisWorkbook.Close()
>
>    Sheet1.Range("A1").Value = -1
>    ThisWorkbook.Save()
> End Sub
>
>
> Is it safe to assume that the code below the
> "ThisWorkbook.Close()" line will NOT be
> executed???    My question is basically:  Does
> all VBA code stop executing once a .Close()
> function is called???
>
> Thank you!
>
> 


0
JLGWhiz
1/24/2010 4:12:48 AM
Yes, try

Public Sub DumbFoo ( )
  Sheet1.Range("A1").Value = -1
  ThisWorkbook.Close SaveChanges:=true
End Sub


-- 
Don Guillett
Microsoft MVP Excel
SalesAid Software
dguillett@gmail.com
"Robert Crandal" <nobody@gmail.com> wrote in message 
news:QgO6n.14679$PI7.6161@newsfe17.iad...
> Please take a look at the code below:
>
> Public Sub DumbFoo ( )
>    ThisWorkbook.Close()
>
>    Sheet1.Range("A1").Value = -1
>    ThisWorkbook.Save()
> End Sub
>
>
> Is it safe to assume that the code below the
> "ThisWorkbook.Close()" line will NOT be
> executed???    My question is basically:  Does
> all VBA code stop executing once a .Close()
> function is called???
>
> Thank you!
>
> 

0
Don
1/24/2010 1:38:33 PM
Reply:

Similar Artilces:

cannot close mail folder
I used to be able to right click on one of several mail folders that I have (not the personal folder) and close this folder. Now when I click on the folder, I get message, "The operation failed. An object could not be found." I went to TOOLS - OPTIONS - MAILSETUP - DATA - FILES - and the folder in question is not even listed. How can I get close this folder out as I used to be able to do? I am using Outlook 2003. Thanks. If the folder isn't listed and you still see it your mail profile became corrupted. The easiest way out is to recreate it in Control Panel-> Mail-...

Access violation when closing a file
Hi, I am running my application in a debugger Windbg and I got the following exception: ******************************************************************************* * * * Exception Analysis * * * ******************************************************************************* *** WARNING: Unable to verify checksum for Recorder.exe *** WARNING: Unable to verify checksum for Reco...

bar graph colors question
Hello everyone, I have data with 5 variables for 10 countries, and I have made a horizontal bar graph for each variable (so 5 graphs). This data is linked to another page, and it is divided by variable within the sheet. For example, the format is: Country Variable 1 US ### China ### India ### UK ### Country Variable 2 US ### China ### India ### UK ### There is a macro that sorts each of this mini-tables, and then each graph draws from its respective variable table. The same 10 countries are in each table, but they are not in th...

Quick Calendar Question
Can calendar permissions be set through the Exchange server (2003), or can this only be done from the client's profile (Outlook 2003)? Thanks, Walt wmckinn@tc2.com It can be done centrally. There are several methods. This one is free and unsupported, etc: http://hellomate.typepad.com/exchange/2003/07/setting_calenda.html And you need to buy these products: http://www.mrhtech.com/software/permission.asp http://www.symprex.com/products/fpm/ -- Neil Hobson Exchange MVP For Exchange news, links and tips, check: http://www.msexchangeblog.com "Walt McKinney" <wmckinn...

VBA
Hi, In our VBA code we used Sheets("xxx") to refer to the data in the sheets in the workbook which has the code. This worked well even if we open several other workbooks thru that code. But suddenly, when we upgraded to Excel 2007, this code no longer worked. Then we refered using ThisWorkbook.sheets("xxxx"). Can anybody know why "ThisWorkbook" keyword is not required in Excel 2003 VBA to refer to the sheets in the same workbook, whereas it is required in Excel 2007 to refer to the sheets ? Thanks, Krishna If you use sheets("xxx") in ...

timechart date question
Is there a way to make historical timecharts in Visio? There seems to be a limit to how far back Visio will go back? I need to chart dates 2000 - 4000 years ago and Visio seems to be limited to 1700 or 1800 onwards. Is there an option or setting to get around this? Thanks! Andrew Jones In fact, Visio is limited to Jan 1, 1900 or later. That is "0" in the date format used by Windows. You'll have to draw them "by hand"...or try to map past dates to future ones and be creative with labeling. -- Lori Pearce Longhorn SDK "Andrew Jones" <andrewmjones@hot...

No Current Record on form close
I think I know what's causing this but not how to fix it. I have a subform tied to my main form and when I close the main form when the subform has no records, I get a "No Current Record" error (no error number, just the text). When I close my form and the subform has associated records, everything is fine. How can I bypass or prevent this dialog box from appearing when I close a main form with no related records in the subform? Thanks! When you close a form with a SubForm, the MainForm closes 1st and then the SubForm will close. Do you have some code in the OnClose or ...

OWA questions #2
A couple of questions I am having problems find the answers to: 1. Is there an easy way to change OWA to be at http://localhost instead of http://localhost/exchange 2. Is there an easy way to change OWA so that the domain name is not required when logging on (as though it is automatically passed)? 3. Are there any good, free, mailbox-to-web archivers out there? Thanks in advance 1. There are a few ways to have it where users type in http://<server>/, and get redirected to http://<server>/exchange. The easiest way is to do a redirection through the IIS console. The followin...

Find and replace question
Dear Members, I have an interesting question related to the functionality of th "replace" command. I have an Excel sheet that has links to anothe Excel sheet in a separate file (or workbook). It is probably easier t refer to the Excel sheet with links as the master sheet and the Exce sheet to be read-in as the feeder sheet to avoid any confusion. I woul like to replace some of the values in the master sheet with alternativ values. However, it can't seem to find the values as the "look in option in replace has only "formulas" as the option, but I can "find th...

How will the Footer div stick to bottom of screen?
I've used CSS for the master page: *** <head runat="server"> <title></title> <asp:ContentPlaceHolder ID="head" runat="server"> </asp:ContentPlaceHolder> <link href="styles.css" rel="stylesheet" type="text/css" /> </head> <body> <form id="form1" runat="server"> <center> <div class="container"> |<div class="header"> | . . . | . . . ...

A performance/progress question on Defrag
I located an old hard drive stored on a shelf the other day and connected it to my Vista machine with a USB dongle. I decided to defrag it (350Gb). Now, I already know that Vista's defrag provides NO indication of progress other than that pretty lame statement that "this may take a few minutes to a few hours". I've seen mention of other defraggers here in this NG and am wondering if any of them provide visual progress indications. Previous OS's used either marching colored blocks, or slowly moving vertical bands in a window. Vista's, on the other ...

Outlook closing
Hi, When I close outlook, it just sits on the little sign saying "outlook exiting". I then have to end the task to exit it. Thanks Try creating a new profile. I am assuming you are running Outlook 2000 http://support.microsoft.com/default.aspx?scid=kb;en-us;195718 "Matt Owen" <mowen@omniis.com> wrote in message news:97ae01c4972f$de422370$a501280a@phx.gbl... > Hi, > > When I close outlook, it just sits on the little sign > saying "outlook exiting". I then have to end the task to > exit it. > > Thanks ...

Question on BCP
I used the following format file in a BCP command: 9.0 21 1 SQLCHAR 0 15 "|" 1 ISILocator SQL_Latin1_General_CP1_CI_AS 2 SQLCHAR 0 21 "|" 2 PaperKey SQL_Latin1_General_CP1_CI_AS 3 SQLCHAR 0 16 "|" 3 ISIKey SQL_Latin1_General_CP1_CI_AS 4 SQLCHAR 0 7 "|" 4 PubYr "" .... 21 SQLCHAR 0 7 "\r\n" 4 TapeYR "" Notice the last line. I wrongly had the data go to the 4th field in the table, when it was supposed to go the 21st field. I expected to find that this fourth field was incorrect. I...

Three questions about sending an email with Access and Outlook 200
I am using Office 2007 on two computers. I want to send an email from an Access program via Outlook. On one computer I am successful. On the second computer I fail. As far as I know the installations of Outlook and Access on the machines are identical. (Obviously this is not true because of the success/fail difference.) My first question is: Instead of using Outlook, is there some other object that I can use to send an email besides Outlook. My Access database contains a table with a list of the email addresses. My email body is: "See attached." and I attach a f...

vba charting question
Suppose I have three range objects, call them XRange, DataRange and DataLabelsRange. - XRange is a series of months, e.g. Jan 2005, Feb 2005 ... etc. - DataRange contains several series of data for each month. For example data for North Sales, South Sales, etc. - DataLabelsRange contains the actual labels "North Sales", "South Sales", etc. The goal is use VBA to create a chart from this ranges with the months on the x axis, lines for each of the series on the y axis, and a legend labeling the lines for you. Pretty simple, no? But after goofing around with the seriesc...

Excel Closes all open excel files when I close one
If I double-click 3 different .xls files to open 3 different excel applictions, I find that they all close at the some time when I close one of the windows. I am closing the windows by clicking the "X" in the upper right corner. I am using Excel 2002 sp2. ...

Outlook Not Closing Completely
I have posted this problem before, as have many others, and apparently there is no solution. When I close Outlook 2000 (completely up to date) running on Windows 2000 Pro (completely up to date), Outlook remains in memory and has to be closed either by the Task Manager or by rebooting. I have exactly the same problem at the office running Outlook 2000 (completely up to date) on Windows XP (completely up to date). There are no PDAs and no COM Add-Ins. I was previously told that the problem was caused by Norton Antivirus, which I was running at both places. However, I replaced Norton with E-Trus...

Question #2
We are a land reseller company implementing Great Plains. We purchase a piece of land and divide it into smaller parts and resell it. At times, after selling the smaller piece of land, it is returned back and we need to resell it again. My question is: How do I implement this in Great Plains. If I consider the land we buy as an item, how do I split it into multiples. The other issue here is that if every land purchased will be a unique item, then our item data is going to grow very fast. Any ideas will be appreciated. Here are a couple of ideas: 1) When you create the Inventory Item...

Easy question?
Hi, Let's supose that I have the following XML: <?xml version="1.0" encoding="utf-8" ?> <root> <element1 type="1"> <element2>some value</element2> <element2>some other value</element2> </element1> <element1 type="2"> <element2>some value</element2> <element2>some other value</element2> <element2>another value</element2> </element1> <element1 type="1"> <element2>one thing</element2> <element2>anything<...

Close Forms
I have a "Main Menu" switchboard style form that has numerous buttons that open forms. Each button opens a form, and each form has a menubar/toolbar that has a "Exit", "Main Menu", "Filter", etc. buttons at the top. Once I open a form and press the "Main Menu" button, the original form stays open. How can I close this form using this "Main Menu" button. I am not sure where the vba code would be. Thank You - Tim In the On Click event of the "Close Form" button, put 2 lines - one to reopen the Main Menu form and on...

Outlook 2002 Opens and Closes
I am trying to help my wife with an Outlook 2002 problem on her machine and I am not having much luck yet. When she opens Outlook it gives you the splash screen and then closes on it's own. She can't actually get into Outlook to use it. She has tried rebooting. Will we have to reload or is there something easier we can try? Thanks! Hi over there, you can choose scanpst.exe to repair you pst. If it isnt work after that. Please reinstall. >-----Original Message----- >I am trying to help my wife with an Outlook 2002 problem >on her machine and I am not having much luck...

Remove User Question
Hi, I have an user on SBS 2003 with an exchange account that I want to remove but I want to keep his email. If I backup exchange to tape via Veritas. Can I restore this mailbox if needed? Thanks On Tue, 2 May 2006 11:21:02 -0600, "matt" <matt@no.com> wrote: >Hi, > >I have an user on SBS 2003 with an exchange account that I want to remove >but I want to keep his email. If I backup exchange to tape via Veritas. >Can I restore this mailbox if needed? > >Thanks > I would export it to a pst and then copy that to something like a CD. On Tue, 2...

Year end closing, V10 BRL SP2
A client has performend a year end closing. During this process het got an SQL memory error, but he continued his work and after a couple of days he asked for help. Thus restore was not an option. I fixed the retainend earning account with KB 871658 and the BS and P&L are o.k., but now a financial detailed history trial balance has no data. Summary is o.k. I found that the detailed information is still in GL20000 table instead of GL30000. Is theire a way to move the detailed information from Open Year to History? -- Toni Hi Toni, Does the failed GL yearend process yiel...

Workflow Close opportunity when order is submitted
Want to create a workflow rule to close an opportunity if an order is submitted for that account. Any suggestions on how to do this appreciated. Thanks ...

Outdook 2003 won't close original message on reply
Hi, When I'm replying to emails, Outlook 2003 won't close the original message. The option to close it is checked. Also, this happens only when the option to use Word as the mail editor is checked. With the internal Outlook mail editor it doesn't happen. Another thing that might be helpfull - when closing email messages, it asks me if I want to save the changes. It happens with almost every email, and of couse, no changes were made. Maybe it is related to the original problem. Any ideas ? Thanks, Marius. Do you get the save prompt when using Outlook as the editor as well...