creating word doc - setting watermark background image on main page and page numbers on the rest
Mostrar comentarios más antiguos
Hi, has anyone done this please?
I've created a word doc using
MATLAB code
wordDoc = invoke(get(wordApp, 'Documents'), 'Add');
and have populated it with tables and images etc.
I've just gone completely thick when trying to get the page numbers and an image on the first page!
Any help (or sympathy) appreciated :-)
Cheers,
Tom
Respuestas (1)
Friedrich
el 13 de Feb. de 2012
0 votos
Hi,
one thing I do when I don't know the code for that is to let Word do a Macro and look at the generated VBA code. In that way you see the commands used to achieve what you like.
So start Word, enable Macro recording, do manually what you want, stop the Macro recording and than look at the VBA code.
This helps in 99% of the cases to get what you want.
5 comentarios
tombola
el 13 de Feb. de 2012
Friedrich
el 13 de Feb. de 2012
The first time I had such a VBA code it took me a while to figure it out. So dont worry about your IQ ;) Best way here is to look up the Mircosoft documentation for the command (here AddPicture)
http://msdn.microsoft.com/en-us/library/aa171535%28v=office.11%29.aspx
You have to expand the "AddPicture method as it applies to the Shapes object". There you see the function call syntax and this is what MATLAB want.
So this
Selection.HeaderFooter.Shapes.AddPicture(FileName:="C:\Tom\background.png" ,LinkToFile:=False, SaveWithDocument:=True)
Should become
Selection.HeaderFooter.Shapes.AddPicture('C:\Tom\background.png',false, true)
Since Left, Top, Width, Height, Anchor are optional you dont have to pass them.
Friedrich
el 13 de Feb. de 2012
So for the BuildingBlockEntries see here:
http://msdn.microsoft.com/en-us/library/bb256797%28v=office.12%29.aspx
So this
ActiveDocument.AttachedTemplate.BuildingBlockEntries("Plain Number 2"). _
Insert Where:=Selection.Range, RichText:=True
should become something like
ActiveDocument.AttachedTemplate.BuildingBlockEntries('Plain Number 2').Insert(wordApp.Selection.Range, true)
tombola
el 14 de Feb. de 2012
Friedrich
el 14 de Feb. de 2012
I am not 100% sure but maybe MATLAB cant resolve that code correctly. maybe try an invoke
invoke(selection.HeaderFooter.Shapes,'AddPicture','C:\Tom\background.png',false, true)
If this doesnt help, can you upload an example (word doc and your ML code) somewhere? So i can play around myself to get it running.
Categorías
Más información sobre Printing and Saving en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!