+ Reply to Thread
Results 1 to 5 of 5

Macro to Screenshot Excel and Paste Image to MS Word

Hybrid View

  1. #1
    Registered User
    Join Date
    08-17-2015
    Location
    Manila
    MS-Off Ver
    2013
    Posts
    10

    Red face Macro to Screenshot Excel and Paste Image to MS Word

    Hello,

    Is there a macro code that will screenshot a specific group of cells in a worksheet and paste it in MS Word as an image when a button is clicked?

    Specific cells - columns A to AJ, rows 1 to 70

    Hoping for your help on this. Thank you.

  2. #2
    Valued Forum Contributor
    Join Date
    12-22-2015
    Location
    HK
    MS-Off Ver
    2010
    Posts
    532

    Re: Macro to Screenshot Excel and Paste Image to MS Word

    Try this:

    HTML Code: 

  3. #3
    Registered User
    Join Date
    08-17-2015
    Location
    Manila
    MS-Off Ver
    2013
    Posts
    10

    Re: Macro to Screenshot Excel and Paste Image to MS Word

    hello, thanks...I will try this now and will get back to you

  4. #4
    Registered User
    Join Date
    08-17-2015
    Location
    Manila
    MS-Off Ver
    2013
    Posts
    10

    Re: Macro to Screenshot Excel and Paste Image to MS Word

    not working

  5. #5
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,838

    Re: Macro to Screenshot Excel and Paste Image to MS Word

    Quote Originally Posted by ramlineses View Post
    Is there a macro code that will screenshot a specific group of cells in a worksheet and paste it in MS Word as an image when a button is clicked?

    Specific cells - columns A to AJ, rows 1 to 70
    That's a huge range to paste as a single picture. While it can be done, the picture would probably be illegible. That said, you could use code like:
    Sub Demo()
    Application.ScreenUpdating = True
    Dim wdApp As Object, wdDoc As Object, StrDocNm As String
    Dim bStrt As Boolean, bFound As Boolean
    'Check whether the document exists
    StrDocNm = "C:\Users\" & Environ("Username") & "\Documents\Document Name.doc"
    If Dir(StrDocNm) = "" Then
      MsgBox "Cannot find the designated document: " & StrDocNm, vbExclamation
      Exit Sub
    End If
    ' Test whether Word is already running.
    On Error Resume Next
    bStrt = False ' Flag to record if we start Word, so we can close it later.
    Set wdApp = GetObject(, "Word.Application")
    'Start Word if it isn't running
    If wdApp Is Nothing Then
      Set wdApp = CreateObject("Word.Application")
      If wdApp Is Nothing Then
        MsgBox "Can't start Word.", vbExclamation
        Exit Sub
      End If
      ' Record that we've started Word, so we can terminate it later.
      bStrt = True
    End If
    On Error GoTo 0
    'Check if the document is open.
    bFound = False
    With wdApp
      'Hide our Word session
      If bStrt = True Then .Visible = False
      For Each wdDoc In .Documents
        If wdDoc.FullName = StrDocNm Then ' We already have it open
          bFound = True
          Exit For
        End If
      Next
      ' If not open by the current user.
      If bFound = False Then
        ' Check if another user has it open.
        If IsFileLocked(StrDocNm) = True Then
          ' Report and exit if true
          MsgBox "The Word document is in use." & vbCr & "Please try again later.", vbExclamation, "File in use"
          If bStrt = True Then .Quit
          Exit Sub
        End If
        ' The file is available, so open it.
        Set wdDoc = .Documents.Open(Filename:=StrDocNm)
        If wdDoc Is Nothing Then
          MsgBox "Cannot open:" & vbCr & StrDocNm, vbExclamation
          If bStrt = True Then .Quit
          Exit Sub
        End If
      End If
      ActiveSheet.Range("A1:AJ70").Copy
      With wdDoc
        'Only now can we can process the document!!!
        .Bookmarks("myBookmark").Range.PasteSpecial , False, 0, False, 9
        .Save
        'Close the document if we opened it
        If bFound = False Then .Close
      End With
      If bStrt = True Then .Quit
    End With
    End Sub
    
    Function IsFileLocked(strFileName As String) As Boolean
      On Error Resume Next
      Open strFileName For Binary Access Read Write Lock Read Write As #1
      Close #1
      IsFileLocked = Err.Number
      Err.Clear
    End Function
    The above code copies A1:AJ70 from the active sheet and pastes it into a Word document named 'Document Name.doc' in your Documents folder, at a bookmark named 'myBookmark'.
    Cheers,
    Paul Edstein
    [Fmr MS MVP - Word]

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Export excel range as image/screenshot in PowerPoint
    By karthikthandapani in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-09-2017, 06:21 AM
  2. Excel VBA to search text in word and paste an image where it finds it
    By andrealbg in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-13-2015, 11:39 AM
  3. Macro to capture screenshot and past and save in word
    By mrorange1 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-05-2015, 09:18 AM
  4. [SOLVED] Paste Excel Userform Screenshot into Word document
    By t0mps in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-19-2014, 07:10 AM
  5. Select Image In Excel Cell and paste to Word Doc Error 438
    By southcraven in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 12-15-2014, 06:48 AM
  6. Copy data range from excel to word as an image (i.e. paste special)
    By papasideris in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-21-2012, 09:54 AM
  7. Copy Paste from Excel to Word distorts image
    By Amphibia07 in forum Excel General
    Replies: 7
    Last Post: 10-29-2009, 11:11 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1