Macro to clear a form

S

sadsfan

I have created a form in Word for writing end of year school reports. I have
made a custom toolbar that contains a save icon and a spellcheck icon. I want
to add an icon (I can do this bit) that when clicked opens a new form. I also
want it to close the old one that has been completed and saved. I tried doing
a macro that always closed window 2 but this didn't work. Any ideas?
 
C

Charles Kenyon

Since the macro will be in the attached template, you will want to start the
new document before you close the old one. Otherwise you may lose your code
when you close the old document.
I am assuming that by Form you mean an online form and not a userform.

Steps I would follow in writing this macro.
' Save old document and assign it to a variable

Application.Dialogs(wdDialogFileSaveAs).Show
Dim oFile As Document
Set oFile = ActiveDocument

' Open new document.and close old
Documents.Add Template:=ActiveDocument.AttachedTemplate.FullName, _
DocumentType:=wdDocument, Visible:=True
oFile.Close
Set oFile = Empty

I haven't tested this except briefly. Hope it helps.
--
Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide

See also the MVP FAQ: http://www.mvps.org/word which is awesome!
--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.
 
S

sadsfan

Charles the only bit that doesn't work is the 'set oFile = Empty' I keep on
getting a Runtime error '424' object required. The rest is great though.
 
C

Charles Kenyon

Then comment the line out. It is intended to save memory Again, I didn't
test it.
--
Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide

See also the MVP FAQ: http://www.mvps.org/word which is awesome!
--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.
 

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