Advertisement
Guest User

Untitled

a guest
Oct 18th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. Sub Macro1()
  2. '
  3. ' Macro1 Macro
  4. '
  5. ' Keyboard Shortcut: Ctrl+w
  6. '
  7. Dim objWord As Word.Application
  8. Dim wordDoc As Word.Document
  9.  
  10. Application.ScreenUpdating = False
  11. Application.EnableEvents = False
  12.  
  13.  
  14. ActiveCell.Copy
  15.  
  16.  
  17. 'Create an Instance of MS Word
  18. On Error Resume Next
  19.  
  20. 'Is MS Word already opened?
  21. Set WordApp = GetObject(class:="Word.Application")
  22.  
  23. 'Clear the error between errors
  24. Err.Clear
  25.  
  26. 'If MS Word is not already open then open MS Word
  27. If WordApp Is Nothing Then
  28. Set WordApp = CreateObject(class:="Word.Application")
  29. Application.Wait (Now + TimeValue("0:00:05"))
  30. End If
  31.  
  32.  
  33.  
  34. 'Handle if the Word Application is not found
  35. If Err.Number = 429 Then
  36. MsgBox "Microsoft Word could not be found, aborting."
  37. GoTo EndRoutine
  38. End If
  39.  
  40. On Error GoTo 0
  41.  
  42. 'Make MS Word Visible and Active
  43. WordApp.Visible = True
  44. WordApp.Activate
  45. Set wordDoc = WordApp.Documents.Add
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55. 'Paste Cell into MS Word
  56.  
  57.  
  58.  
  59. Set Destination = wordDoc.Content
  60. Destination.Collapse Direction:=wdCollapseStart
  61. Destination.PasteSpecial DataType:=wdPasteText
  62.  
  63.  
  64. EndRoutine:
  65. 'Optimize Code
  66. Application.ScreenUpdating = True
  67. Application.EnableEvents = True
  68.  
  69. 'Clear The Clipboard
  70. Application.CutCopyMode = False
  71. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement