PDA

View Full Version : Solved: Setting ActiveDocument.Saved after Print (IOW: "stop bugging me word!")



bstephens
07-14-2011, 04:07 PM
Often times I open a document (has lots of field codes) and all I do is print it and then close it. However, every time after I print it, I always get a prompt, "do you want to save the document" upon a close event even though the only thing I did was print it. Kind of annoying.

Does anyone see problems with re-purposing the FilePrint command to get around the problem?

Sub FilePrint()
oldSaved = ActiveDocument.Saved
Dialogs(wdDialogFilePrint).Show
ActiveDocument.Saved = oldSaved
End Sub
BTW: I am good on the field codes always being updated as they are already handled by a separate "AutoOpen" macro that updates all my fields in StoryRanges upon an open event.

However, are there other things I am not thinking about that could cause a problem for me?

Thanks,
-B

Frosty
07-14-2011, 06:05 PM
You'll also need to repurpose FilePrintDefault, I believe (the one that doesn't show the dialog), using ActiveDocument.PrintOut.

And I'm pretty sure this won't give you everything you want in Word 2010 (since printing changes pretty dramatically with the advent of file print/page setup combo under the new workspace concept).

But I don't think there's an worry in what you want to do above, except that you should always always use Option Explicit, and thus be required to Dim oldSaved as Boolean in that routine.

bstephens
07-15-2011, 09:06 AM
Thanks Frosty. For anyone out there, this was the code I used.

Sub FilePrint()
Dim oldSaved As Boolean
oldSaved = ActiveDocument.Saved
Dialogs(wdDialogFilePrint).Show
ActiveDocument.Saved = oldSaved
End Sub

Sub FilePrintDefault()
Dim oldSaved As Boolean
oldSaved = ActiveDocument.Saved
ActiveDocument.PrintOut
ActiveDocument.Saved = oldSaved
End Sub

bstephens
07-17-2011, 06:55 PM
Does anyone have a macro that will convert manually typed numbering (or "hard numbering") into auto numbering by applying applicable paragraph styling?

Ideally what I am trying to accomplish is have the macro loop through each paragraph, and if the starting characters in the paragraph range "look" like numbering then the macro will apply a style (i.e. "Article_L1, etc.) with an auto number component to it.

Further example:



1. This is a sentence --> [macro applies Article_L1 style]
1.1 This is another sentence --> [macro applies Article_L2 style]
1.1.1 --> This is another sentence --> [macro applies Article_L3 style.]
etc.

I have been struggling with the code below trying to get it to work, I think the problem has to do with whitespace in the range, but I am not sure.

Sub HardNumberingtoAutoNumbering()
'draft - this needs alot of work
Dim i As Long
Dim oRng As Word.Range
Dim oParRng As Word.Range

Set oRng = ActiveDocument.Range
For i = 1 To oRng.Paragraphs.Count
Set oParRng = oRng.Paragraphs(i).Range
With oParRng
If .Characters.First Like "[0-9]" Then
.Collapse wdCollapseStart
.MoveEndUntil Cset:="[a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I,J,K,L ,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z]", Count:=wdForward
'.Delete - eventually the hard numbering needs to be deleted

'this doesn't seem like the right way to do it.
If oParRng Like "#.?" Or _
oParRng Like "##.?" Then
.Style = ActiveDocument.Styles("Article_L1")

ElseIf oParRng Like "#.#?" Or _
oParRng Like "#.##?" Or _
oParRng Like "##.#?" Or _
oParRng Like "##.##?" Then
.Style = ActiveDocument.Styles("Article_L2")

'Debugging Purposes
Else: MsgBox (oParRng & " Not triggered.")
End If

End If
End With
Next i
End Sub
Anyone have a macro that functions similarly to this or have pointers on how to make this work in a flexible way (ex: macro indifferent as to whether user typed in the "hard numbering" with spaces or tabs)

I have attached a template with the "Article..." styles I want to apply
http://dl.dropbox.com/u/1534325/Normal.dotm

Regards,
Brian