The print button has VB which sets up the variables for the text boxes
on the form then more vb which places the results from the variables
onto an A4 sheet. The VB then prints the sheet and closes the document
without saving it (as it doesn't need saving after printing). It then
closes word. The two lines of code I use to achieve the two closures
are:
ActiveDocument.Close (wdDoNotSaveChanges)
Application.Quit
Here's the full code for the print button:
Private Sub PrintBtn_Click()
'sets variable for each txtBox on form, just to make it easer
vName = Form.txtName
vAmount = Form.TxtAmount
vAmount2 = Form.TxtAmount2
vFor = Form.TxtFor
'Goes to each field on form and sets results equal to variables
ActiveDocument.FormFields("bkName").Result = vName
ActiveDocument.FormFields("bkAmount").Result = vAmount
ActiveDocument.FormFields("bkAmount2").Result = vAmount2
ActiveDocument.FormFields("bkFor").Result = vFor
'Remove Form from screen
Form.Hide
'Prints the form
Selection.EndKey Unit:=wdStory
Application.PrintOut FileName:="", Range:=wdPrintCurrentPage,
Item:= _
wdPrintDocumentContent, Copies:=1, Pages:="",
PageType:=wdPrintAllPages, _
Collate:=True, Background:=True, PrintToFile:=False
'Closes document and Word
ActiveDocument.Close (wdDoNotSaveChanges)
Application.Quit
End Sub
It all works fine except that my dilemma is that if there are other
word documents open, it will go through the closure procedure
(obviously as I'm using Application.Quit) and it asks if you want to
save the other open documents before exiting (as word usually does
when you close word without saving first).
This is no big deal for me, but as this document is set up for
clients, I don't want to tell them to just press Yes to save the
document/s or Cancel to keep the document/s open and keep working on
them, as they are the type of client who will get confused and press
No instead and lose their work.
If I take out the application.quit code and if there are no other open
documents, then the client is left with an open session of word with
no document open. This would confuse my clients even more!!
So far I have made this document as smooth as possible for them - they
open it, fill in four fields, press print and it automatically prints
and closes (without saving). Simple! But if other documents are
already open...
Is there an IF Statement I can use (in place of the two 'close'
commands) that asks:
if
there are other open documents besides 'this one'
then
leave them open and close this one without saving it
else
close word without saving this document'
(ie ActiveDocument.Close (wdDoNotSaveChanges)
Application.Quit)
End If
I hope this makes sense.
Thanks
If you can help, please reply to post in
microsoft.public.word.vba.general
Frig I'm Dumb!!!
Original post in microsoft.public.word.word97vba:
ActiveDocument.Close (wdDoNotSaveChanges)
If Documents.Count = 0 Then
Application.Quit
End If
?
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site www.gmayor.com
Word MVP web site http://word.mvps.org
Yes, exactly that.
Thank you! It works perfectly
Therefore I somehow need to get rid of the Amount2 bookmark and
replace it with some conversion on the Amount bookmark somewhere else
on the page. I could use Ref bkAmount \* DollarText but this doesn't
give me the word "Dollars".
I have found the following macros but how do I run a macro to convert
a ref field automatically? The first macro assumes you're selecting
the text first.
<a href="http://groups.google.com.au/group/
microsoft.public.word.conversions/browse_thread/thread/
51f2a90faa801a4b/811c432a00eac36c?lnk=st&q=convert+number+to+text+in
+word+group%3A*word*#" Conversion of currency to english words in MS
word</a>
Or do I keep the Amount2 bookmark but instead of asking for the value
via the form (vAmount2) do I run some code that references the vAmount
figure, converts it and places it in bkAmount2?
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Wow! That's amazing. It worked. This should be referenced on Word
MVPS!!!
Thank you very much Graham for all your help!!
> See the item Formatting cash amounts in words on my web pagehttp://www.gmayor.com/formatting_word_fields.htm
>
> --
> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
> Graham Mayor - Word MVP
>
> My web sitewww.gmayor.com
> Word MVP web sitehttp://word.mvps.org