Any way to close a UserForm from another macro or with sendkeys?

S

src

Hi there,

I have a routine that opens a new document based on a template.

This template has an autonew macro that shows a userform. Normally
this is exactly what I want from this template. But when it's opened
from another document, I'd like to bypass the userform.

Is there a way to skip the userform altogether? If not, is there a
way to automatically close it once it opens?

I've tried sending a simple SendKeys "{ESC}", True, but it appears
that userforms don't respond to this and it won't execute until after
the form is (manually) closed.

THANKS
 
E

Edward Thrashcort

<hack mode on>

Can you modify the auto open macro to detect that the calling document is
active and only show the userform when it is?

If there is a state where the calling document could be open and yet you
still don't want the form to display, set a document variable in the calling
document before it opens the new document and test its setting with the auto
open macro. Remember to unset the variable once the document has been
loaded.

<hack mode off>

Eddie
 
S

src

Thanks, Eddie.

I thought about the very things you mentioned, but I don't know how to
implement them.

I set a document variable in the calling document, but once the new
doc is opened the variable doesn't exist. Seems that document
variables are not available across multiple documents.

I also tried using the "set" parameter on a variable thinking that
thay may make the variable available for the Word session and not just
the calling document.

Can you think of a way to set a variable and have it available in a
new document?

THANKS,
Matt
 
E

Edward Thrashcort

I thought it was the new document that runs the auto open macro?
If so, this macro can access the document variable like this for example

if Documents("caller.doc").Variables("newdoc_opened") = True then

Eddie
 

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