BJ said:
Jean-Guy,
the logo file contains 2 logos which are jpg file and also has 4 text
description lines. I tried to change my codes, but the logo file still can't
be closed somehow.
You need to organize this logo file so that the information is easily
retrieved.
I would place the logos and their descriptions in a table. I would make sure
that the logos were inline with text (because they are easy to work with).
in the original template, the old logo is saved in a document object. that's
Floating or inline?
why my code has to use a loop to close the other documents not only the logo
file.
What other documents? I thought there were only two documents: The one that
needs its logos updated and "logos.doc"
???
all the 'copy' and 'paste' parts work, but only the 'close' doesn't work.
"doesn't work" does not mean anytjing. What happens exactly when you get to
the line that causes the error (which line?)?
Why don't you use a simpler line like:
oLogoFile.Close wdDoNotSaveChanges
???
Set regCur = Selection.Range
This line creates a range that refers to the actual selection in the
original document.
Set oLogoFile = Application.Documents.Open("C:\Program
Files\HRForms\logos.doc")
pos1 = oLogoFile.Paragraphs(1).Range.Start
pos2 = oLogoFile.Paragraphs(4).Range.End
Set regCur = oLogoFile.Range(Start:=pos1, End:=pos2)
Now, regCur that refered to a range in the original document, is now
pointing to the first 4 paragraphs in "logos.doc".
Why set it twice if the first setting is not used at all?
regCur.Copy
Application.Documents(thisDoc).Activate
Application.Documents(thisDoc).Shapes("Object 8").Select
Application.Selection.ShapeRange.Delete
Can't these three lines be replaced by:
thisDoc.Shapes("Object 8").Delete
???
Application.Documents(thisDoc).Shapes("Object 2").Select
Application.Selection.ShapeRange.ScaleWidth 1.71, msoFalse,
msoScaleFromBottomRight
Application.Selection.ShapeRange.ScaleWidth 0.94, msoFalse,
msoScaleFromTopLeft
Application.Selection.ShapeRange.ScaleHeight 0.81, msoFalse,
msoScaleFromTopLeft
Application.Selection.ShapeRange(1).OLEFormat.DoVerb
VerbIndex:=wdOLEVerbPrimary
Application.Selection.WholeStory
Application.Selection.Delete Unit:=wdCharacter, Count:=1
Application.Selection.PasteSpecial Link:=False, Placement:=wdInLine,
DisplayAsIcon:=False
Application.Selection.TypeBackspace
Again, as I wrote twice already, do not use "Activate" when dealing with
mutliple documents, it just causes headaches.
For the last part of your code, try something like this:
With thisDoc.Shapes("Object 2")
.ScaleWidth 1.71, msoFalse, msoScaleFromBottomRight
.ScaleWidth 0.94, msoFalse, msoScaleFromTopLeft
.ScaleHeight 0.81, msoFalse, msoScaleFromTopLeft
.OLEFormat.Edit
Set objectDoc = .OLEFormat.Object
End With
With objectDoc
With .Range
.Delete
.PasteSpecial Link:=False, Placement:=wdInLine, DisplayAsIcon:=False
End With
.Close
End With
oLogoFile.Close wdDoNotSaveChanges
Set oLogoFile = Nothing
Set regCur = Nothing
Set regCur = Nothing
Application.Documents(oLogoFile).Close wdDoNotSaveChanges
Set oLogoFile = Nothing
Application.Documents("Document in " & thisDoc).Close
thisDoc is a document, not a string as expected in the parenthesis. You
probabably need "Document in " & thisDoc.Name). But you should use something
like I suggest above instead, you have more control that way.