Export Images in Excel Comment to Word with VBA Questrion?

MXL

Board Regular
Joined
Jun 15, 2010
Messages
67
hi,

I was able to with the following VBA code, quickly export all comments in text format of active worksheet to the Word document.
Sub CopyCommentsToWord()
'Update 20140325
Dim xComment As Comment
Dim wApp As Object
On Error Resume Next
Set wApp = GetObject(, "Word.Application")
If Err.Number <> 0 Then
Err.Clear
Set wApp = CreateObject("Word.Application")
End If
wApp.Visible = True
wApp.Documents.Add DocumentType:=0
For Each xComment In Application.ActiveSheet.Comments
wApp.Selection.TypeText xComment.Parent.Address & vbTab & xComment.Text
wApp.Selection.TypeParagraph
Next
Set wApp = Nothing
End Sub


Now, I want to export images also within those comment tags that I have in that excel workbook, is there something that i need to add in that existing vba code above which will enable me to extract just images from the comments within those cells?

Thank you for taking the time to read this, much appreciated, look forward to hearing from you

Vladmir

<tbody>
</tbody>
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
This line:
wApp.Selection.TypeText xComment.Parent.Address & vbTab & xComment.Text
in your existing code is explicitly extracting only the comment text.

Try something along the lines of:
Code:
Sub CopyCommentsToWord()
Dim xComment As Comment, wApp As Object, bVis As Boolean
On Error Resume Next
Set wApp = GetObject(, "Word.Application")
If Err.Number <> 0 Then
  Err.Clear
  Set wApp = CreateObject("Word.Application")
End If
On Error GoTo 0
With wApp
  .Visible = True
  .Documents.Add DocumentType:=0
  For Each xComment In Application.ActiveSheet.Comments
    With xComment
      bVis = .Visible
      .Visible = True
      .Shape.CopyPicture
      .Visible = bVis
    End With
    With .ActiveDocument.Range
      .Collapse 0
      .Paste
      .InsertAfter vbCr
    End With
  Next
End With
Set wApp = Nothing
End Sub
PS: When posting code, please use the code tags, accessed via the # button on the posting menu.
 
Upvote 0
hi Macropod,

Thank you so much, works great, I apologize for posting the VBA code in bad format, one last thing if I may, in that VBA code you wrote, is it possible to export to word the cell location from which that image had been exported from i.e ($a$1) for a cell that has a comment located in cell a1?, because from the initial VBA code i pasted, it also exports to word the cell location in which that comment is located, then the text.

Where would you have to add this line of VBA code within your VBA code in order to have the cell location exported to word along with the image?

Thank you again, look forward to hearing from you.

Regards,

Vladmir
 
Upvote 0
You could insert:
.InsertAfter xComment.Parent.Address & Chr(11)
before:
.Collapse 0
 
Upvote 0

Forum statistics

Threads
1,214,981
Messages
6,122,565
Members
449,089
Latest member
Motoracer88

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top