Outlook WordEditor Range.Paste overwrites previous paste
Mostra commenti meno recenti
I posted this on stackoverflow as well, not sure if that's against the rules or in bad form.
What I'm trying to do:
- From Matlab, open a new email (Outlook 2010)
- Create a chart and copy it to clipboard
- Paste that image to the email
- Repeat steps 2 and 3 a couple more times to paste additional charts
Problem: Pastes after the first simply overwrite the existing image. I have tries this with text as well, getting the same overwrite.
What I think I need: a way to advance the "cursor" or set the range or selection before each paste such that it excludes the existing image/text (essentially goes to the end of the document).
Code:
Get current running instance of Outlook, create a new email and get its WordEditor:
h = actxGetRunningServer('outlook.application');
mail = h.CreateItem('olMail');
mail.To = 'someone@somewhere.com';
mail.Subject = 'subject line text';
mail.BodyFormat = 'olFormatHTML';
word_editor = mail.GetInspector.WordEditor;
mail.Display
Open Matlab figure, copy to clipboard, close:
F = open('fig.fig');
print(F,'-clipboard','-dmeta')
close(F)
Paste clipboard:
word_editor.Range.Paste
Up to this point everything works. Any additional copy/pastes after this simply overwrite the previous paste.
I have tried things like adding paragraphs, attempting to get the current range to maybe find a way to change it but no luck.
Any assistance will be greatly appreciated.
4 Commenti
Walter Roberson
il 24 Gen 2017
I would expect this behavior. The range does not automatically change after a paste, since you might want to make other changes to what was pasted such as formatting or color changes.
Tony L.
il 24 Gen 2017
Walter Roberson
il 24 Gen 2017
It looks to me as if you should use the Collapse method, specifying wdCollapseEnd, which would position you just after the end of the range. Then Paste would paste after the range. If you then collapsed again you should be ready to paste again.
Tony L.
il 25 Gen 2017
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Environment and Settings in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!