+ Reply to Thread
Results 1 to 10 of 10

Embedded OLEObject (Word) in Excel export to pdf after changing it

Hybrid View

  1. #1
    Registered User
    Join Date
    12-13-2020
    Location
    Belgium
    MS-Off Ver
    2016
    Posts
    7

    Embedded OLEObject (Word) in Excel export to pdf after changing it

    Hello, I'm new here
    I'm duth (from Belgium) so my Englisch is not quit good but I'll try to do my best.
    I hope you can think about this when there's an answer and keep your answer extremely simple :-) but I'll do my best to understand al your answers.

    I need help with a code, vba, for making a macro.
    I can't find any solutions of it so I hope the experts here can help me :-)

    So, i have an excel-file.
    On one of the sheets (blad1) I have an embedded Word OLEObject.
    I can change this object instantly in excel but I want to save it as a pdf-file everytime there are changes on de object.

    Can anybody help me to make a code?
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor
    Join Date
    09-30-2018
    Location
    Vlaams Brabant Belgium
    MS-Off Ver
    365
    Posts
    456

    Re: Embedded OLEObject (Word) in Excel export to pdf after changing it

    Hoi,

    Sub OpslaanNaarPDF()
    '
    ' OpslaanNaarPDF Macro
    ''
       Dim obj As Object, FilePath As String, FileExists As String
    '
       Blad1.Shapes.Range(Array("Object 9")).Select
       'Selection.Verb Verb:=xlOpen
       Set obj = Selection.Object
       FilePath = "H:\MyDoc.pdf"
       
       FileExists = Dir(FilePath)
       If FileExists <> "" Then
          FilePath = InputBox("Bestand bestaat reeds, Geef de naam op die je wenst te gebuiken", "Opgelet bestand bestaat reeds", FilePath)
       End If
       
       obj.SaveAs2 FilePath, 17
        
    End Sub
    Last edited by Joske920; 12-13-2020 at 03:05 PM.
    Please be as complete as possible in your asking so it may save use all the time to rework the solution because you didn't give all the requirements. If you have a layout in mind please work it out first so we can adapt our solution to it. Thanks.
    If you have been helped, maybe you could click the *

  3. #3
    Registered User
    Join Date
    12-13-2020
    Location
    Belgium
    MS-Off Ver
    2016
    Posts
    7

    Re: Embedded OLEObject (Word) in Excel export to pdf after changing it

    Thanks Joske,

    the code crashes on the line
    Set obj = Selection.Object
    Can you help me further with this?

  4. #4
    Valued Forum Contributor
    Join Date
    09-30-2018
    Location
    Vlaams Brabant Belgium
    MS-Off Ver
    365
    Posts
    456

    Re: Embedded OLEObject (Word) in Excel export to pdf after changing it

    It did work for me when I made it but not when you open the excel and strait click the button

    I reworked that. Its a bit ugly but it does work
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    12-13-2020
    Location
    Belgium
    MS-Off Ver
    2016
    Posts
    7

    Re: Embedded OLEObject (Word) in Excel export to pdf after changing it

    Thanks a lot Joske. Heel erg bedankt Joske !
    I was only struggeling for searching the object-name. I found it by richt-click on the object - assign macro - and there was the name

    It worked fine for me.
    I will also share this link on a dutch forum.

  6. #6
    Registered User
    Join Date
    12-13-2020
    Location
    Belgium
    MS-Off Ver
    2016
    Posts
    7

    Re: Embedded OLEObject (Word) in Excel export to pdf after changing it

    Joske, I want to ask you something about the script.
    If I wanne cancel the Saving

    I get a message:
    "fout 4198 tijdens uitvoering" (=dutch)

    Can you solve this ?

  7. #7
    Valued Forum Contributor
    Join Date
    09-30-2018
    Location
    Vlaams Brabant Belgium
    MS-Off Ver
    365
    Posts
    456

    Re: Embedded OLEObject (Word) in Excel export to pdf after changing it

    Hi

    add the folowing line above -> obj.SaveAs2 FilePath, 17

       If FilePath = vbNullString Then Exit Sub

  8. #8
    Registered User
    Join Date
    12-13-2020
    Location
    Belgium
    MS-Off Ver
    2016
    Posts
    7

    Re: Embedded OLEObject (Word) in Excel export to pdf after changing it

    ok, thanks again :-)

  9. #9
    Registered User
    Join Date
    12-13-2020
    Location
    Belgium
    MS-Off Ver
    2016
    Posts
    7

    Re: Embedded OLEObject (Word) in Excel export to pdf after changing it

    Hi Joske920, another question
    Is there a way to make a msgbox if the file saved succesfully?

    "hhr succesfull saved"

  10. #10
    Registered User
    Join Date
    12-13-2020
    Location
    Belgium
    MS-Off Ver
    2016
    Posts
    7

    Re: Embedded OLEObject (Word) in Excel export to pdf after changing it

    Ok, I found it !
    simpely put the code MsgBox

    Private Sub OpslaanAlsPDF_click()
    
    ' OpslaanNaarPDF Macro
    
    Dim Oobj As OLEObject, obj As Object, FilePath As String, FileExists As String
    
    Blad4.Shapes.Range(Array("Object 10")).Select  '' AANPASSEN indien nodig - Blad (hier Blad4) en object (hier Object 10)
       
    'Selection.Verb Verb:=xlOpen
    FilePath = "C:\JVC\HHR.pdf"  ''AANPASSEN indien nodig
    Set Oobj = Selection
       
    Oobj.Activate
       
    Blad4.Activate  ''AANPASSEN indien nodig - Blad (hier Blad4)
    Blad4.Cells(1, 1).Select ''AANPASSEN indien nodig - Blad (hier Blad4)
       
    Set obj = Oobj.Object
    
    FileExists = Dir(FilePath)
    
    If FileExists <> "" Then
        FilePath = InputBox("Geef naam/adres in die je wilt gebruiken", "Opgelet bestand bestaat al", FilePath)
    End If
        
    If FilePath = vbNullString Then Exit Sub
       
       obj.SaveAs FilePath, 17  ''17=PDF
       MsgBox "Saved succesfully !"
    
       
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 0
    Last Post: 11-10-2016, 10:18 AM
  2. Function changing the text value of OLEObject Textbox
    By Stephen Dougherty in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 08-24-2015, 03:15 PM
  3. Embedded excel in word
    By Djp189 in forum Excel General
    Replies: 2
    Last Post: 02-18-2015, 09:54 PM
  4. Play embedded OLEObject WAV synchronously
    By DaveMackmiller in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-28-2014, 01:29 PM
  5. Replies: 0
    Last Post: 01-25-2013, 07:03 AM
  6. [SOLVED] Excel with an embedded Word Doc
    By Scream in forum Excel - New Users/Basics
    Replies: 0
    Last Post: 08-02-2006, 11:40 AM
  7. word OLEObject in excel
    By daron in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-22-2005, 08:38 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1