Home > Software engineering >  VBA while saving word file with multiple images as pdf only 1 image gets visible in pdf
VBA while saving word file with multiple images as pdf only 1 image gets visible in pdf

Time:04-26

I have a vba code that is able to open a word docx file and save it as pdf. If however there are multiple images in the original word document only 1 image is rendered in the PDF. If I do a manual "save as pdf" from the Word all images are rendered without issue. The following is the code snip of the convert/save function

Function ConvertFiletoPDF(DocName As String) As String
On Error GoTo 0
Dim wApp As Object, wDoc As Object
Dim fname
Dim sendname
  
  Set wApp = CreateObject("Word.Application")
  wApp.Visible = False
    
  Set wDoc = wApp.Documents.Open(DocName, ReadOnly:=True)
    
fname = InStr(1, DocName, ".")

sendname = Left(DocName, fname - 1)   ".pdf"
'  wApp.ActiveDocument.CompatibilityMode
   
 ' wApp.ActiveDocument.SaveAs sendname, 17
  
  wApp.ActiveDocument.ExportAsFixedFormat _
        outputfilename:=sendname, _
        exportformat:=17
wApp.Quit SaveChanges:=0
Set wApp = Nothing




 ConvertFiletoPDF = sendname








End Function
 function 

Appreciate any input the community can provide

Regards

CodePudding user response:

The Document.ExportAsFixedFormat method takes a lot of parameters, so I'd suggest playing with them. Moreover, you can use a macro recorder to find out what properties and methods are called when you do the required operation manually, so you could find out what values are passed as parameters. I'd suggest playing with WdExportOptimizeFor and WdExportOptimizeFor enumeration values that can be passed to the method.

Also you may take a look at the Document.ExportAsFixedFormat2 method.

CodePudding user response:

The solution thanks to the help and advice of Eugene and the Macro Recorder was to resave the word file in non compatible mode and then do the save as pdf

Thanks

  • Related