Guest User

Untitled

a guest
Apr 25th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. on AddAttachmentFileToWordDoc(FilePath, Extension, Filename)
  2. set GraphicFiles to {"PDF", "jpg", "giff", "TIFF", "gif", "png", "PPM", "PGM", "PNM"}
  3. set VideoFiles to {"mov", "wmv", "amv", "mp4", "m4p", "mpg", "mpeg", "m4v"}
  4. tell application "Microsoft Word"
  5. activate
  6. tell active document
  7. --Part 1. Works great. No hidden characters making up a link
  8. set ContTemp to content of text object
  9. set StartRange to (count of ContTemp) - 1
  10. set endrange to StartRange
  11. set theRange to create range start StartRange end endrange
  12.  
  13. -- Part 2. This works almost perfectly, except for the file paths
  14. tell theRange
  15. if GraphicFiles contains Extension then
  16. --this works well
  17. make new inline picture at end with properties {file name:FilePath as text, save with document:true}
  18.  
  19. else -- everything else, Word docs, excel, etc.
  20. set CommentText to "Click here to open attachment " & Filename
  21. --This file path gave me trouble
  22. --set FilePath to "../../../../../../Desktop/EmailStorage/AttachmentStorage/" & Filename
  23. --This file path works relative to the Word document, though I rather use something like the above
  24. set FilePath to "AttachmentStorage/" & Filename & " "
  25. make new hyperlink object at end with properties {text to display:CommentText, hyperlink address:FilePath, text object:theRange}
  26. end if
  27. end tell
  28. end tell
  29.  
  30. --Part 3. Does not work well. I can't figure out how to get the range that includes the link
  31. tell active document
  32. set EndOfEmail to return & return & " End of Email" & return as string
  33. set ContTemp to content of text object
  34. set StartRange to (count of ContTemp) - 1
  35. set endrange to StartRange
  36. set theRange to create range start StartRange end endrange
  37. set style of theRange to style normal
  38. set content of theRange to EndOfEmail
  39. end tell
  40. end tell
Add Comment
Please, Sign In to add comment