Creating image file from Word document failing

pbassett

Active Member
Joined
May 5, 2004
Messages
358
This Excel VBA code used to work perfectly for over 100 Word documents displaying metrics that consist of several shapes, charts, etc.
The goal is to save the Word document as an image file since the monitor that displays the metrics don't support Word.
But now .PasteSpecial results in only the partial document remaining when the image file is created. I have NO idea how this happened.

Code:
With wdapp.Selection
    .WholeStory
    .Copy
    .PasteSpecial Link:=False, DataType:=wdPasteEnhancedMetafile, Placement:=wdInLine, DisplayAsIcon:=False
End With
 
Last edited:

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Intrigued by your code :confused:
- I have not seen this method used previously
- I gave it a go and it worked as expected
- I was unable to recreate your issue using Office 2016

This is what I did..
- new Word document created
- some shapes, a smart-shape, some text, an Excel Table and a chart inserted
- document saved and closed
- document opened via VBA (run from Excel)
- your code converted everything (excl header and footer) into a single image
- image could be manually saved in 5 different formats

Is the problem caused by something in the Word document ?
- I presume you are re-using documents and inserting updated metrics
- try re-creating ONE of the problem documents from scratch

Follow-up

1. Let me know how you get on
2. Purely for my enlightenment :) ...which code are you using to create the image files?
 
Upvote 0
A different method
- starting over :eeek: may not appeal to you, but the method I use to create similar images is via PowerPoint
- design each slide to contain required shapes, charts, tables etc
- each slide is converted to a separate image file

To convert every slide in the active presentation to images...
Code:
Sub ConvertSlidesToImages()
    Const fPath = "c:\test\MetricImages"
    Const fName = "metric_"
    Dim slideNo As Integer

    With Application.ActivePresentation
        For slideNo = 1 To .Slides.Count
            .Slides(slideNo).Export fPath & "\" & fName & slideNo & ".jpg", "JPG"
        Next slideNo
    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,178
Members
453,021
Latest member
Justyna P

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