Bonjour,
Dans son message, < Chris Joyce > écrivait :
In this message, < Chris Joyce > wrote:
See inline comments.
|| wdApp.Documents(1).Activate
||
Here you activate the first document of the Word instance you created at the
top of the code...
|| '_______________________________________
|| ' Do the page print setup
.... and you assign the whole document range to a range object called
DocRange
|| Set DocRange = wdApp.ActiveDocument.Range
|| With DocRange.PageSetup
|| .LineNumbering.Active = False
|| .Orientation = wdOrientPortrait
|| .TopMargin = CentimetersToPoints(0.5)
|| .BottomMargin = CentimetersToPoints(0.5)
|| .LeftMargin = CentimetersToPoints(2)
|| .RightMargin = CentimetersToPoints(1.81)
|| .Gutter = CentimetersToPoints(0)
|| .HeaderDistance = CentimetersToPoints(1.25)
|| .FooterDistance = CentimetersToPoints(1.25)
|| .PageWidth = CentimetersToPoints(21)
|| .PageHeight = CentimetersToPoints(29.7)
|| .FirstPageTray = wdPrinterDefaultBin
|| .OtherPagesTray = wdPrinterDefaultBin
|| .OddAndEvenPagesHeaderFooter = False
|| .DifferentFirstPageHeaderFooter = False
|| .VerticalAlignment = wdAlignVerticalTop
|| .SuppressEndnotes = False
|| .MirrorMargins = False
|| .TwoPagesOnOne = False
|| .BookFoldPrinting = False
|| .BookFoldRevPrinting = False
|| .BookFoldPrintingSheets = 1
|| .GutterPos = wdGutterPosLeft
|| End With
||
|| '_______________________________________
|| ' Find any Arial and replace it with Times New Roman
|| ' ***************
|| ' this dose not work at the moment
|| ' ***************
Why do you reset DocRange to exactly the same thig as above?
|| Set DocRange = wdApp.ActiveDocument.Range
You initialize a find with DocRange...
||
|| With DocRange.Find
|| .ClearFormatting
|| .Replacement.ClearFormatting
|| .Format = True
|| .Font.Name = "Arial"
|| .Replacement.Font.Name = "Times New Roman"
|| .Text = ""
|| .Replacement.Text = ""
|| .Forward = True
|| .Wrap = wdFindContinue
|| .MatchCase = False
|| .MatchWholeWord = False
|| .MatchWildcards = False
|| .MatchSoundsLike = False
|| .MatchAllWordForms = False
|| End With
|| wdApp.Selection.Find.Execute Replace:=wdReplaceAll
....but do the .Execute on wdApp ???
Never tried that! This might be the problem!
This code is different from the one you posted initially (thew one that
worked on my machine).
Which one are you really using? This one or the one posted before?
Try with
.Execute Replace:=wdReplaceAll
just before the
EndWith
above, and of course remove the
wdApp.Selection.Find.Execute Replace:=wdReplaceAll
line.
Same comments for your Windings replace below as the comments written above.
||
|| '_______________________________________
|| ' Find any N/A winddings and replace it with Times New Roman
|| ' they are all part of the form
|| ' ***************
|| ' this dose not work at the moment
|| ' ***************
||
|| Set DocRange = wdApp.ActiveDocument.Range
|| With DocRange.Find
|| .Font.Name = "Wingdings"
|| .Replacement.Font.Name = "Times New Roman"
|| .Text = "N/A"
|| .Replacement.Text = "N/A"
|| .Forward = True
|| .Wrap = wdFindContinue
|| .Format = True
|| .MatchCase = False
|| .MatchWholeWord = True
|| .MatchWildcards = False
|| .MatchSoundsLike = False
|| .MatchAllWordForms = False
|| End With
|| wdApp.Selection.Find.Execute Replace:=wdReplaceAll
||
||
Here, just to make your code more efficient, remove all the wdApp from the
beginning of each line, put a
With wdApp
before
.Documents.Open FileName:=CurrentProject.Path & "\output\" & FindMe &
".doc"
(Where the wdApp has been removed) and add a
End With
after
.Quit
(Where the wdApp has been removed).
Don't forget to make sure that each line between the "With wdApp" and "End
With" starts with a "." (dot).
||
|| '_______________________________________
|| ' Save then close
|| wdApp.Documents(1).SaveAs (CurrentProject.Path & "\output\" & FindMe)
|| wdApp.Documents(1).Close
||
|| '_______________________________________
|| ' Open the full student report and set AllowOnlyReading protection
|| ' ***************
|| ' work out how to save with AllowOnlyReading protection
|| ' ***************
|| wdApp.Documents.Open FileName:=CurrentProject.Path & "\output\" & FindMe
&
|| ".doc"
|| wdApp.Documents(1).Activate
|| ' wdApp.Documents(1).ProtectionType = wdAllowOnlyReading
|| wdApp.Documents(1).Save
|| wdApp.Documents(1).Close
||
|| varBookmark = rstStudent_T.Bookmark
|| rstStudent_T.Move 1
|| Wend
|| rstStudent_T.Close
||
|| wdApp.Quit
|| '_______________________________________
||
|| MsgBox ("Done")
||
|| End Sub
--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site:
http://www.word.mvps.org