Hello, I have a macro that I use that saves the selected email as a PDF, i tried to add to it so that it will turn all of the text in the email black, and re-size the images. If i set the document to visible the code works fine, but for some reason when I have visible:=false I get an error when trying to edit the email. This is the beginning of the code I have.
Sub SaveMessageAsPDF()
MapHDrive
'Select the messages to process and run this macro
Dim olMsg As MailItem
'Create the folder to store the messages if not present
If CreateFolders(strPath) = False Then GoTo lbl_Exit
'Open or Create a Word object
On Error Resume Next
Set wdApp = GetObject(, "Word.Application")
If Err Then
Set wdApp = CreateObject("Word.Application")
bStarted = True
End If
On Error GoTo lbl_Exit:
For Each olMsg In Application.ActiveExplorer.Selection
SaveAsPDFfile olMsg, wdApp
Next olMsg
lbl_Exit:
If bStarted Then wdApp.Quit
Set wdApp = Nothing
Exit Sub
End Sub
Sub SaveAsPDFfile(olItem As MailItem, wdApp As Object)
Dim FSO As Object, TmpFolder As Object
Dim tmppath As String
Dim strfilename As String
Dim strAttachPrefix As String
Dim strName As String
Dim oRegEx As Object
'Get the user's TempFolder to store the temporary file
Set FSO = CreateObject("Scripting.FileSystemObject")
tmppath = FSO.GetSpecialFolder(2)
'construct the filename for the temp mht-file
strName = "email_temp.mht"
tmppath = tmppath & "\" & strName
'Save temporary file
olItem.SaveAs tmppath, 10
'Open the temporary file in Word
Set wdDoc = wdApp.Documents.Open(Filename:=tmppath, _
AddToRecentFiles:=False, _
Visible:=False, _
Format:=7)
This is what I am trying to add
Selection.WholeStory
With Selection
.Font.Color = -587137025
End With
Dim pic As InlineShape
For Each pic In wdApp.ActiveDocument.InlineShapes
With pic
pic.LockAspectRatio = msoTrue
If pic.Width > wdApp.InchesToPoints(6.5) Then
pic.Width = wdApp.InchesToPoints(6.5)
Else ' vertical
End If
End With
Is it possible to do the edits to the document while it isn't visible? Also, do i need to add an If statement to check if there are any inlineshapes to prevent an error?