Word VBA: Cum se editeaza o poza selectata de utilizator ?

Informatii despre cum se utilizeaza Microsoft Word 2003. Editare, formatare, automatizare de documente
Închis
Green eyes
Mesaje: 36
Membru din: Mie Dec 30, 2009 1:45 pm
Localitate: Timişoara

Word VBA: Cum se editeaza o poza selectata de utilizator ?

Mesaj de Green eyes » Vin Apr 23, 2010 3:26 pm

Salutare,

As avea nevoie de ajutorul vostru, am postat mesajul de mai jos pe cateva forumuri despre VBA Word, dar respectivii experti au raspuns ca nu cunosc VBA Word :evil: . Pai, atunci cum considera ei ca sunt experti ? Ma puteti voi ajuta ? Va multumesc anticipat.

Hello all,

I need your help. I have got a Word 2000 file, a report in which I insert various pictures. Document is quite long (up to 60 pages) and number of pictures is also significant, up to 40 pictures. To avoid having a huge file in the end (~ 30 MB), I need to edit each picture, taking following steps:

A). Select the picture (this is done by the user, not by the macro), CTRL + X;
B). Paste Special – Picture;
C). Select the picture, CTRL + X, Paste Special, Picture (JPEG);
D). Picture cropping on right hand side (5.25 units) + picture cropping on bottom side (2.65 units);
E). Select the picture, then Text Wrapping, Top and bottom;
F). Save the document.

I have tried to solve it, by recording a macro, the issue is that it stops after step B. I guess it stops because right after step B picture is not anymore selected, therefore the routine stops.

Here is the code I have got:

Cod: Selectaţi tot

Sub JPEGs()
'
' JPEGs Macro
   
    Selection.Cut
    Selection.PasteSpecial Link:=False, DataType:=wdPasteMetafilePicture, _
        Placement:=wdFloatOverText, DisplayAsIcon:=False
    Selection.Cut
    Selection.PasteSpecial Link:=False, DataType:=15, Placement:= _
        wdFloatOverText, DisplayAsIcon:=False
    Selection.ShapeRange.PictureFormat.CropRight = 5.25
    Selection.ShapeRange.PictureFormat.CropBottom = 2.65
    Selection.ShapeRange.WrapFormat.Type = wdWrapTopBottom
    ActiveDocument.Save
End Sub
When I run it, it just stops on second “Selection.Cut”, error generated is: Run-time error ‘4605’. This method or property is not available because the object is empty.

Could you please help me to make it work ?

Or is there any other solution, to avoid having huge Word 2000 files, after inserting many, many pictures ?

Please note that I do not want this macro to apply these steps/editing to all pictures intersted into the file, I just want it to apply the changes to ONLY ONE picture I select, nothing else. Thank you in advance and have a nice day.

Dr.Windows
Moderator
Moderator
Mesaje: 4570
Membru din: Vin Iul 31, 2009 7:32 am

Re: Word VBA: Cum se editeaza o poza selectata de utilizator ?

Mesaj de Dr.Windows » Vin Apr 23, 2010 3:36 pm

Intr-un fel este "normal" sa nu mai mearga incepand de la al 2-lea "cut"... pentru ca atunci se "rupe filmul" deoarece nu mai exsita acel "selection".
Cred ca ar trebui sa mearga daca userul executa pasii A-C (sau daca reusesti sa "identifici" prin cod acel nou obiect "picture" rezultat din "paste special"...

E puitin mai greu de realizat dar nu imposibil... sa vad daca reusesc sa gasesc o solutie (asta daca nu cumva reuseste altcineva sa-ti raspunda intre timp)...

Dr.Windows
Moderator
Moderator
Mesaje: 4570
Membru din: Vin Iul 31, 2009 7:32 am

Re: Word VBA: Cum se editeaza o poza selectata de utilizator ?

Mesaj de Dr.Windows » Vin Apr 23, 2010 5:08 pm

Ar mai fi o varianta... fara VBA, daca asta o poti considera o alternativa pentru problema ta: "Compress Pictures" - selectand o poza, la optiunea Format Picture ai butonul "Compress" ce iti da posibilitatea sa comprimi TOATE pozele din document dintr-o singura "miscare" ca in poza atasata:
CompressPictures.jpg
Si daca alegi din lista "web/screen" si "all pictures in document" se va ocupa word-ul sa converteasca toate pozele.

Din pacate aceasta optiune nu este utilizabila prin VBA, ai sa observi ca recorderul VBA nu iti va inregistra si proprietatile pe care doresti sa le aplici... dar avand macar o poza selectata poti afisa fereastra de compresia folosind comanda:

Cod: Selectaţi tot

Sub DeschideFereastraCompress()
    CommandBars.FindControl(ID:=6382).Execute
End Sub
Vei reusi astfel sa mai reduci din dimensiunea documentului...
Nu aveţi permisiunea de a vizualiza fişierele ataşate acestui mesaj.

MrDoitsafe
Mesaje: 8
Membru din: Mar Iul 27, 2010 7:27 am

Re: Word VBA: Cum se editeaza o poza selectata de utilizator ?

Mesaj de MrDoitsafe » Mar Iul 27, 2010 11:11 am

A). Select the picture (this is done by the user, not by the macro), CTRL + X;
B). Paste Special – Picture;
C). Select the picture, CTRL + X, Paste Special, Picture (JPEG);
D). Picture cropping on right hand side (5.25 units) + picture cropping on bottom side (2.65 units);
E). Select the picture, then Text Wrapping, Top and bottom;
F). Save the document.

I have tried to solve it, by recording a macro, the issue is that it stops after step B. I guess it stops because right after step B picture is not anymore selected, therefore the routine stops.

Here is the code I have got:

Cod: Selectaţi tot

Sub JPEGs()
'
' JPEGs Macro
   
    Selection.Cut
    Selection.PasteSpecial Link:=False, DataType:=wdPasteMetafilePicture, _
        Placement:=wdFloatOverText, DisplayAsIcon:=False
    Selection.Cut
    Selection.PasteSpecial Link:=False, DataType:=15, Placement:= _
        wdFloatOverText, DisplayAsIcon:=False
    Selection.ShapeRange.PictureFormat.CropRight = 5.25
    Selection.ShapeRange.PictureFormat.CropBottom = 2.65
    Selection.ShapeRange.WrapFormat.Type = wdWrapTopBottom
    ActiveDocument.Save
End Sub
Pai stai putin, tu acolo ai inregistrat un Macro, dar acesta vad ca face intai Cut apoi Paste as metafile apoi iarasi Cut apoi Paste as raster. Nu are sens, de ce vrei sa dai Paste as metafile? Imaginile sunt raster, banuiesc, metafile e pentru format vector.
Prin urmare se seimplifica treaba si cu al doilea Cut (daca inteleg bine).
Deci: dupa selectia facuta de user, urmeaza Selection.Cut si apoi Paste as raster.

Vezi functia PasteSpecial aici:
http://msdn.microsoft.com/en-us/library ... e.11).aspx

Banuiesc ca ai dat din greseala Paste as metafile si apoi ai revenit, dar Word a inregistrat tot, fireste.

Închis

Înapoi la “Intrebari despre Word 2003”