To close a Word doc?

E

Ed from AZ

I have a VB6 app that opens a Word doc (Word 2000) and set the focus
to the doc. For ease of use while using this program, I wanted to be
able to close the doc with a single-key input. Word already has CTRL
+W and CTRL+F4, but it would be easier to use just one single key. I
was thinking of the accent/tilde key, since I won't be using it while
running my VB app.

I tried to capture the keystroke in my VB app - but realized that the
Word doc is active, so the keystroke gets inserted into the doc,
rather than being seen by the VB app. When the doc is opened, the VB
form is set to Visible = False, and reset to Visible = True when the
doc is closed.

So I need a way to map Word's Close command to a different keystroke
only while running this VB app, and release it when the app closes.
Or can I retain focus on the VB app so it can read the keystroke, even
though the Word doc is in front of the form? How do I approach this?

Ed
 
S

Steve Barnett

Ed from AZ said:
I have a VB6 app that opens a Word doc (Word 2000) and set the focus
to the doc. For ease of use while using this program, I wanted to be
able to close the doc with a single-key input. Word already has CTRL
+W and CTRL+F4, but it would be easier to use just one single key. I
was thinking of the accent/tilde key, since I won't be using it while
running my VB app.

I tried to capture the keystroke in my VB app - but realized that the
Word doc is active, so the keystroke gets inserted into the doc,
rather than being seen by the VB app. When the doc is opened, the VB
form is set to Visible = False, and reset to Visible = True when the
doc is closed.

So I need a way to map Word's Close command to a different keystroke
only while running this VB app, and release it when the app closes.
Or can I retain focus on the VB app so it can read the keystroke, even
though the Word doc is in front of the form? How do I approach this?

Ed

From a purely personal point of view, I would get very agitated if I pressed
a key on the keyboard and my word document disappeared. I'd probably resort
to a quick virus scan which would probably identify the app as a keylogger
so I'd delete it (ok, extreme reaction - but I've worked with government
departments who do such things).

I would suggest you deal with this at the Word end - create a template that
adds a button to the Word tool bar to close and exit Word. The user can
press this button if THEY want to and will get results that THEY expect
rather than something that a programmer thought would be a cool feature.

As a seasoned user of Word though, I would prefer to retain control over my
document once I've been dumped in to Word and would prefer not to have
someone else take control off me.

If you must handle it from your app then one approach would be to, rather
than hide your form, display an always-on-top form (there are loads of
references to how to do that in this forum) with a single button on it
stating "Close Document and Exit Word". When the user presses it, you
programmatically close the files and Word. If the user manually closes Word
then you need to detect that and remove your always on top window.

The down side is that the button sits on top of everything so, if the user
goes and does something else, your button sits on top, but that's the price
you pay for convenience.

Steve
 
E

Ed from AZ

Hi, Steve. I guess I didn't explain deep enough. Thsi is not going
out to any type of distribution - I will be the only user. This is an
app I've created simply for my own personal use for one specific
function. I am a musician in my church worship team. All of our
music is on single printed pages, and I have to riffle through a 3-
inch binder when a song is called out that's not on the list.

So I got the Word docs for all these songs and created a VB app that
will allow me to find these songs and pull them up on my laptop. I'm
using a search-as-you-type module that I found online - I've posted a
few questions about it on the VB forum. The app finds titles and
lines that match what I type which come up in a series of combo boxes,
and I then hit a number key to tell the app to open the file shown in
_that_ combo box.

When the doc opens, a Timer checks to see if I have a "doc" object
with a name; when the name string comes up blank because the doc has
been closed, the Timer sets the Word object Visible = False and brings
the app forward to get the next song.

I just wanted to try to cut down the number of keystrokes. It's a bit
awkward to hit CTRL+W and then Shift+2 for the next song (I use
numbers 1 - 8 and also Shift + [1-8]). If I could remap one key to
the Word Close command for this app only, and release that when I'm
done, it would help me a bit.

Ed
 
N

Norm

Ed,

Do a search for Hotkey at Randy's site.

http://vbnet.mvps.org/

Norm
Hi, Steve. I guess I didn't explain deep enough. Thsi is not going
out to any type of distribution - I will be the only user. This is an
app I've created simply for my own personal use for one specific
function. I am a musician in my church worship team. All of our
music is on single printed pages, and I have to riffle through a 3-
inch binder when a song is called out that's not on the list.

So I got the Word docs for all these songs and created a VB app that
will allow me to find these songs and pull them up on my laptop. I'm
using a search-as-you-type module that I found online - I've posted a
few questions about it on the VB forum. The app finds titles and
lines that match what I type which come up in a series of combo boxes,
and I then hit a number key to tell the app to open the file shown in
_that_ combo box.

When the doc opens, a Timer checks to see if I have a "doc" object
with a name; when the name string comes up blank because the doc has
been closed, the Timer sets the Word object Visible = False and brings
the app forward to get the next song.

I just wanted to try to cut down the number of keystrokes. It's a bit
awkward to hit CTRL+W and then Shift+2 for the next song (I use
numbers 1 - 8 and also Shift + [1-8]). If I could remap one key to
the Word Close command for this app only, and release that when I'm
done, it would help me a bit.

Ed
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top