Is this a new as yet unsaved document

L

liz

I want to be able to have a cancel button on a user form that as well
as unloading the form will identify if the document (Word 2003) is a
new document that has never yet been saved. The form will run as part
of Autonew, if the user cancels the document can be scrapped when it
is a new one i.e. closed without saving. However the form will also be
availabel as a button on a toolbar for using with existing documents,
in this circumstance the form must be unloaded but the document will
remain for the user to work with.

So the question is how do I identify this is a brand new and as yet
unsaved document?

thank you

luca
 
G

Graham Mayor

If you are testing as part of an autonew macro then the document will always
be unsaved at that point (unless the autonew macro code saves it)?

If your created form contains any changes that have not been saved then
simply closing the document will force a warning prompt to save the
document. If it is 'brand new' and nothing has been entered it will just
close.

Sub CancelForm()
ActiveDocument.Close
End Sub

Clearly I am missing something here? :(

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
L

liz

If you are testing as part of an autonew macro then the document will always
be unsaved at that point (unless the autonew macro code saves it)?

If your created form contains any changes that have not been saved then
simply closing the document will force a warning prompt to save the
document. If it is 'brand new' and nothing has been entered it will just
close.

Sub CancelForm()
ActiveDocument.Close
End Sub

Clearly I am missing something here? :(

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web sitewww.gmayor.com
Word MVP web sitehttp://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

Graham,

Thank you for replying. Autonew will do something like this: show
form, then save document.
In some cases the user will cancel the operation and the form should
close and the document "disappear.
But the form will also be avaialble to the user with an existing
document. In this case if he selects cancel the form should unload and
the user should be left with the document as if he never opened the
form.

So either I need to identify when it is part of AutoNew - can I do
this? - or perhaps this will work:

If ActiveDocument.Path = "" Then
ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges
Unload Me
Exit Sub
End If

what do you think? luca
 
J

Jonathan West

I want to be able to have a cancel button on a user form that as well
as unloading the form will identify if the document (Word 2003) is a
new document that has never yet been saved. The form will run as part
of Autonew, if the user cancels the document can be scrapped when it
is a new one i.e. closed without saving. However the form will also be
availabel as a button on a toolbar for using with existing documents,
in this circumstance the form must be unloaded but the document will
remain for the user to work with.

So the question is how do I identify this is a brand new and as yet
unsaved document?

If ActiveDocument.Path = "" Then
'The document has never been saved
Else
'It has
End If


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 
S

Shane

I want to be able to have a cancel button on a user form that as well
as unloading the form will identify if the document (Word 2003) is a
new document that has never yet been saved. The form will run as part
of Autonew, if the user cancels the document can be scrapped when it
is a new one i.e. closed without saving. However the form will also be
availabel as a button on a toolbar for using with existing documents,
in this circumstance the form must be unloaded but the document will
remain for the user to work with.

So the question is how do I identify this is a brand new and as yet
unsaved document?

thank you

luca

Hi Luca.

This is the code I use for my userform Cancel buttons. It doesn't
matter whether the document has been modified by other code or not as
my standard code works for every userform.

This is modified code originally downloaded elsewhere.

'#################################
Private Sub cmdCancel_Click()
'#################################

Dim Msg, Style, Title, Help, Ctxt, Response, MyString

Msg = "NOTICE:" & vbCrLf & "If you abort then all changes will be
lost." & vbCrLf & "Do you really want to abort?"
Style = vbYesNo + vbCritical + vbDefaultButton2
Title = "Document Abort"

Response = MsgBox(Msg, Style, Title)

If Response = vbYes Then ' User chose Yes.
ActiveDocument.Saved = True ' Mark doc as saved to close cleanly
Unload Me ' Unload Msgbox
ActiveDocument.Close ' Unload active document
End If

End Sub
 
S

Shane

I want to be able to have a cancel button on a user form that as well
as unloading the form will identify if the document (Word 2003) is a
new document that has never yet been saved. The form will run as part
of Autonew, if the user cancels the document can be scrapped when it
is a new one i.e. closed without saving. However the form will also be
availabel as a button on a toolbar for using with existing documents,
in this circumstance the form must be unloaded but the document will
remain for the user to work with.

So the question is how do I identify this is a brand new and as yet
unsaved document?

thank you

luca

Hi Luca.

This is the code I use for my userform Cancel buttons. It doesn't
matter whether the document has been modified by other code or not as
my standard code works for every userform.

This is modified code originally downloaded elsewhere.

'#################################
Private Sub cmdCancel_Click()
'#################################

Dim Msg, Style, Title, Help, Ctxt, Response, MyString

Msg = "NOTICE:" & vbCrLf & "If you abort then all changes will be
lost." & vbCrLf & "Do you really want to abort?"
Style = vbYesNo + vbCritical + vbDefaultButton2
Title = "Document Abort"

Response = MsgBox(Msg, Style, Title)

If Response = vbYes Then ' User chose Yes.
ActiveDocument.Saved = True ' Mark doc as saved to close cleanly
Unload Me ' Unload Msgbox
ActiveDocument.Close ' Unload active document
End If

End Sub
 

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