Outlook WordEditor Range.Paste overwrites previous paste
이전 댓글 표시
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
Walter Roberson
2017년 1월 24일
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.
2017년 1월 24일
Walter Roberson
2017년 1월 24일
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.
2017년 1월 25일
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Environment and Settings에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!