Can't Close and Delete Open MSWord 2010 Document (ActiveDocument.Close prevents Kill command from running.) - ms-word

I'm trying to close the open word document and delete it as part of my DocumentBeforeClose event. I keep running across the following code in my searches (+/- some error trapping statements):
Dim Killfile As String
Killfile = Dir$(ActiveDocument.FullName)
If Len(Dir$(Killfile)) > 0 Then
SetAttr Killfile, vbNormal
ActiveDocument.Close False
Kill Killfile
End if
I've found similar code (well, frankly almost identical code) in several places, and everyone seems to confirm that it works, but I cannot get it to run correctly in my own attempts, regardless of what module I have the code in. When run, the document always closes, but the code also stops there and never gets to the Kill command. In theory the instance of Word is supposed to keep running the script once the document closes; in my case the instance is open, but there's nothing running anymore at that point. Am I doing something obviously wrong here?
If it's helpful, in another version of the code I'm working with I have a Do While loop going through a directory and deleting documents containing "temp.doc" in the name. That code has no trouble running through and deleting closed files, but also will not delete the active/open document after closing.
Is this something I need to place in the Normal module in order for it to work? (Would reeeaally like to avoid that if possible). Thanks for any help!
Editing to add the top few relevant Search Results from Googling "MSWord VBA Delete Open Document":
http://word.tips.net/T001346_Deleting_the_Open_Document_File.html
http://geekgirls.com/2010/02/deleting-an-open-document-in-microsoft-word/
Delete doc when macro finishes
Again, the unifying factor appears to be:
Activedocument.close
Kill WhateverOpenFile
...which just plain doesn't seem to make sense.

Related

How to get rid of the commands bringed by VS code terminal over and over

I have no idea why, but my VS code terminal keeps bringing in the history the same commands that I have used one day. So, every time I open the VS code, instead of bringing me the last used commands in that specific directory/project, it brings me the commands that I used once. It's the same commands, over and over.
That happens even if in the terminal is printed
**Session contents restored from 5/17/2022 at 3:29:45 PM**
They are actually not
Can someone help?

Prevent Ctrl+Z deleting last line in SSMS after Script As->Alter View

I'm hoping there's just some way to disable this in SQL Server Management Studio (v17.9.1). When I Script As->Alter a view or stored procedure to a new query window, I can hit Ctrl+Z and it deletes the last line of text! I realize as I'm trying to explain this exactly what's happening: Sql is opening a new window and "pasting" the query line by line. Therefore when you undo you're removing the last line and so on.
This becomes a problem when you say, alter a view, make changes and execute, then decide to undo them all so you just hold Ctrl+Z then realize you've erased half your script instead of just going back to the starting point.
Does anyone know how to disable this or an elegant way of preventing it from happening?
This started out as a comment, but it's getting too long, so...
I don't think you can disable ctrl+z, but just like Newton's third law of motion - for every undo there's an equal and opposite redo - so if you've held ctrl+z pressed for too long, you can always restore the lines that ctrl+z deleted simply by using ctrl+y.
Other options are suggested by GSerg in his comments - you can always keep a copy of the original code in a different query window, or even a simple text editor.
One more option is to first save the content of the new query to a file, so you can always reload it's original state if you've messed things up too much.

How do you cope with emacs halting on receiving big input?

I am developing project in clojure using emacs cider under windows. And sometimes I have a problem that after accidently forgotten println function or on printing contents of big file Emacs stops responding (cursor and all key combinations doesn't work) and retire into oneself for processing that information to show it in repl. The only way to continue I know is to close program and open project files from scratch. And it is so simple to get in this trap.
Are there any other better solutions or configuration restrictions?
Though this suggestion will not solve your problem completely, it can help you a little.
First, set *print-length* to some value to limit the number of items of each collection to be printed.
(set! *print-length* 10)
And use cider-connect instead of cider-jack-in. You should run lein repl in a separate console window, then run cider-connect to connect to the repl. Then you can evaluate some expressions in the console window.
It would be good if there's an option to limit the contents to be printed by number of characters, however, I couldn't find it.

Oddball issue arising with use of TextWrangler to edit Python 2.7 script which tests multithreading and Queue modules

I'm writing a script in Python 2.7 exploring the use of the multithreading and Queue modules. the script just defines two functions, one of which will be started in a thread instance to fill a Queue, and a second one which will be started in a second thread instance to pull something off the Queue. However, I cannot even get this script to execute, as it chokes on one of the function definitions even before it executes. The code snippet with the problem is:
def listenThread(counter):
while queue.empty() != True:
try:
outcome = queue.get()
print outcome
counter -=1
print counter
except:
return 'queue.get() command loop failing.'
The error message I am getting is:
$ python threading-and-queue-test.py
File "threading-and-queue-test.py", line 34
except:
^
IndentationError: unindent does not match any outer indentation level
$
I've searched SO and checked the docs for correct formation of the try-except construct, and it seems OK. I had earlier versions of the code (without the try-except ) working, so I am getting suspicious about the text editor, TextWrangler v4.0.1.
Can anyone suggest a debug approach or code correction?
Thanks!
Red
As you have already suspected, it is most likely an indentation error. Your text editor is probably mixing the use of tabs and spaces. Replace all tabs with spaces (or vice versa though the standard in python is 4 spaces) and you should see the error disappear.
For those who find this question later like I did it's easy to fix TextWrangler's settings and stop this issue altogether; Go to "Preferences" -> "Editor Defaults" -> "Auto-expand tabs" then set tabs to 4 spaces. Restart TextWrangler for changes to take affect. For existing documents that continue giving you a problem read this.

Running octave in Emacs

I am using run-octave in Emacs to trigger octave. Something is acting abnormally.
Every time I hit TAB to complete, there would be a tailing ^M; If I edit a .m file using edit a.m, it would start a new frame instead of a new buffer and the prompt is waiting for the closure of that frame so it would not respond to any input. How could I configure .emacs so that run-octave would behave normally?
Any comment is appreciated!
You seem to have two problems. I'm not sure about the trailing ^M, which seems to be caused by some sort of Windows/Unix CR/LF problem, but maybe I can help with the second problem.
The edit command uses the EDITOR environment variable to decide what to run. It seems that yours is either set to emacsclient or has defaulted to it. You haven't said whether you're on Unix or Windows, so I'm going to assume the former: you'll have to change this a bit for Windows.
To avoid the waiting thing, try running octave with a different EDITOR. For example, try out running
EDITOR='emacsclient -n' octave
When you type edit foo, it should bring up an Emacs buffer (if you want a new frame as well, use -c too) but not wait until you're done.
If this fixes things for you, you could change your ~/.bashrc to include the line
export EDITOR='emacsclient -n'