Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 08-18-2024, 09:23 AM
ksor ksor is offline Strange (for me at least) errors in Excel VBA Windows 10 Strange (for me at least) errors in Excel VBA Office 2016
Advanced Beginner
Strange (for me at least) errors in Excel VBA
 
Join Date: Feb 2018
Location: Århus V, Denmark
Posts: 78
ksor is on a distinguished road
Angry Strange (for me at least) errors in Excel VBA

I have cooked up this VBA code to send a part of the sheet as a outlook mail:


Code:
Sub SendNamedRangeAsPictureInBody()
    Dim OutlookApp As Object
    Dim OutlookMail As Object
    Dim WordEditor As Object
    Dim ws As Worksheet
    Dim strRange As String
    Dim rng As Range
    Dim InlineShape As Object

    ' Define your sheet and named range here
    Set ws = ThisWorkbook.Sheets("Bla Bla")
    strRange = "ToBookKeeping"
    
    ' Get the range
    Set rng = ws.Range(strRange)

    ' Copy the range as a picture
    rng.CopyPicture Appearance:=xlScreen, Format:=xlPicture

    ' Create the Outlook application and email
    Set OutlookApp = CreateObject("Outlook.Application")
    Set OutlookMail = OutlookApp.CreateItem(0)

    ' Construct the email
    With OutlookMail
        .To = "BookKeepersMailAddress"
        .Subject = "Hjemmeladning for den angivne periode !"
        

        ' Get the Word editor for the email and paste the image
        Set WordEditor = OutlookMail.GetInspector.WordEditor
        WordEditor.Content.Paste
        
        ' Access the last pasted inline shape (the picture) and resize it
        Set InlineShape = WordEditor.InlineShapes(WordEditor.InlineShapes.Count)
        InlineShape.LockAspectRatio = msoFalse
        InlineShape.Width = InlineShape.Width * 2 ' Double the width
        InlineShape.Height = InlineShape.Height * 2 ' Double the height
            
        WordEditor.Content.InsertAfter vbCrLf & vbCrLf '& vbCrLf
    
        ' Add additional text or formatting here if needed
        WordEditor.Content.InsertAfter "Fortsat god dag !" & vbCrLf & "TEAM SUPPORT"
    
        
        .Display    ' Display the email before sending
        '.Send       '  At sende giver FEJL !!!!!!!!!!!!!!!

    End With

    ' Clean up
    Set ws = Nothing
    Set rng = Nothing
    Set OutlookMail = Nothing
    Set OutlookApp = Nothing
    Set WordEditor = Nothing
    Set InlineShape = Nothing
   
End Sub

In my FIRST try it worked nicely BUT only as a .DISPLAY of the mail - I had to click on the SEND button to send it !


If I used the .SEND command instead of .Display I got this error:
"Invalid procedure call or argument"
in the .Send line !


OK, I then tried to search out there and found others with the same problem and they were adviced to update MSOffice (and thereby Outlook) and so I did ...




and now I have ANOTHER error in the line:


Set WordEditor = OutlookMail.GetInspector.WordEditor


the error is: Run-time error '-2147467259 (80004005)'


What is wrong here ?
Reply With Quote
  #2  
Old 08-19-2024, 09:59 PM
ksor ksor is offline Strange (for me at least) errors in Excel VBA Windows 10 Strange (for me at least) errors in Excel VBA Office 2016
Advanced Beginner
Strange (for me at least) errors in Excel VBA
 
Join Date: Feb 2018
Location: Århus V, Denmark
Posts: 78
ksor is on a distinguished road
Default

No one have any ideas ?
Reply With Quote
  #3  
Old 08-20-2024, 07:21 AM
ksor ksor is offline Strange (for me at least) errors in Excel VBA Windows 10 Strange (for me at least) errors in Excel VBA Office 2016
Advanced Beginner
Strange (for me at least) errors in Excel VBA
 
Join Date: Feb 2018
Location: Århus V, Denmark
Posts: 78
ksor is on a distinguished road
Default

I tried again this morning and ...


The "DISPLAY-version" works again WITHOUT the "new after-update error" !!!


Still the same error in the "SEND-version"
Reply With Quote
  #4  
Old 08-21-2024, 06:47 AM
ksor ksor is offline Strange (for me at least) errors in Excel VBA Windows 10 Strange (for me at least) errors in Excel VBA Office 2016
Advanced Beginner
Strange (for me at least) errors in Excel VBA
 
Join Date: Feb 2018
Location: Århus V, Denmark
Posts: 78
ksor is on a distinguished road
Default

Nothing is wrong - it has to do with MS changing all this _BEEP_ concerning security !
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Strange (for me at least) errors in Excel VBA Strange character in text copied from excel AndreHaak Word 6 05-16-2019 02:40 PM
Change excel background color, strange... sojiro Excel 7 04-18-2018 10:07 AM
Strange (for me at least) errors in Excel VBA Strange Excel Behaviour with ACE OLEDB Provider Abumushfiq Excel 1 06-30-2014 04:20 AM
Strange (for me at least) errors in Excel VBA Inexplicable automation errors in Word and Excel RichardP Word VBA 4 08-16-2012 07:38 PM
Strange errors omirza Excel 0 02-05-2010 01:30 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 11:19 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft