Results 1 to 8 of 8
  1. #1
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,329

    Conversion From Word To JPG

    Hi Guy's I have found this code then adapted to my folders and files etc....

    This converts word to jpg, appears to do the job nicely, however when i try and open the jpg file after conversion in MS Paint, it says:

    Paint cannot read this file, this is not a valid bitmap file, or its format is not currently supported

    When I have gone into the property of another JPG file, it opens fine in paint, yet the file extension looks the same, eventually i am going to try and:

    Convert a document to jpg
    Add to email body (i can achieve this part once the file opens with MS Paint)

    Code:
    Dim WDDoc As ObjectDim WD As Object
    Dim strPath As String, strFile As String, strJPGFile As String
    
    
    strPath = "T:\DMT Ltd\Word Docs\Word To JPG\"
    strFile = "Absence Request Form.docx"
    strJPGFile = Replace(strFile, ".docx", ".jpg")
    
    
        WDarray = Array("txtCompName", "txtCompNo", "txtCompRef", "txtRefTitle", _
        "txtCompName", "txtStorage", "txtSpecial", "txtCompRef", "txtSafeRef", "txtStreet", "txtStreetNo", "txtPostNo", "txtCity")
                 
        Set WD = CreateObject("Word.Application")
        WD.Visible = True
        Set WDDoc = WD.Documents.Open(strPath & strFile)
        Set objSelection = WD.selection
    
    
        WD.Activate
        WDDoc.ExportAsFixedFormat strPath & strJPGFile, 17 ' 17 is wdExportFormatPDF
        WDDoc.Close
        WD.Quit
        Set WDDoc = Nothing
        Set WD = Nothing
        
        Application.FollowHyperlink strPath
    This converts but unsure why a JPG wont open in pain due to file extension!!!

    I am going to try BMP format

    Any ideas if there is a better option than my adapted code ?

  2. #2
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,235
    Just changing the extension of a file does not "convert" it into another type. Your code changes the extension from .docx to .jpg, exports the Word document as PDF and you expect it to be a picture. I am afraid it is not that easy...

    Here are some links for you to read:
    https://www.wikihow.com/Change-a-Wor...to-JPEG-Format
    https://www.groovypost.com/howto/sav...eg-image-file/

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  3. #3
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,281
    Dave,
    Change your name to Daphne.

    Does that change your sex?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  4. #4
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,329
    Thanks Vlad, just found some info on google that to me read it could be done but, by the sounds of it, vba converting file extensions when i guess all im doing is renaming the file

    It does remove the docx image but it makes sense that its renaming it therefore still a word doc but not recognized

    hahahha WGW sorry WGM

    it sounds like i have confirmed what i though by the above (renaming)

    I like the pun though

    As always, kind of you guy's to respond

    Davina

  5. #5
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,861
    Davina,

    How about saving your word doc as html and insert that into the body of your email?
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  6. #6
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,329
    @noke123 hahahha I maybe be Debbie, Davina, but i think i will remain as Dave

    Yes that would be fab, is that an easy task ?

  7. #7
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,329
    Just found this that can adapt, well hopefully

    Code:
    Dim objWord AsObject
        Set objWord = CreateObject("Word.Application")
        objWord.Visible =True
        objWord.Documents.Open "D:\OfficeDev\Test\SaveAsHtml.docx"
    
        objWord.ActiveDocument.SaveAs2 Filename:="D:\OfficeDev\Test\SaveAsHtml.htm", FileFormat:= _
            wdFormatFilteredHTML, LockComments:=False, Password:="", AddToRecentFiles _
            :=True, WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts _
            :=False, SaveNativePictureFormat:=False, SaveFormsData:=False, _
            SaveAsAOCELetter:=False, CompatibilityMode:=0
        
        objWord.ActiveDocument.Close     objWord.Quit

  8. #8
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,329
    I have found a different method to give the same result, don't rename files etc as you guys suggest there is no conversion, just add the word doc to email body

    this does do that which is very close to what i was trying to achieve, when the document goes to the mail body, it is full screen, is there a method I can make it half screen ?

    Would it be the case of editing the word doc or can i add a resize option in VBA ?

    this works apart from full screen on mail body

    Code:
    Dim myApp As New Outlook.ApplicationDim OutAccount As Outlook.Account
    Dim MyItem As Outlook.MailItem
    Dim wd As Object, editor As Object, doc As Object
    
    
    strPath = "T:\DMT Ltd\Word Docs\Word To Mail\"
    strFile = "Absence Request Form.docx"
    
    
    
    
    
    
        Set wd = CreateObject("Word.Application")
        Set doc = wd.Documents.Open(strPath & strFile)
        doc.Content.Copy
        doc.Close
        Set wd = Nothing
        
        Set MyItem = myApp.CreateItem(olMailItem)
        Set OutAccount = myApp.Session.Accounts.Item(1)
        With MyItem
            .BodyFormat = olFormatRichText
            Set editor = .GetInspector.WordEditor
            editor.Content.Paste
            .Display
        End With

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 3
    Last Post: 06-27-2017, 12:06 PM
  2. Replies: 6
    Last Post: 08-13-2014, 10:32 PM
  3. Replies: 8
    Last Post: 04-14-2013, 01:33 PM
  4. Call word object and import word fields
    By silverspr in forum Programming
    Replies: 3
    Last Post: 12-10-2012, 11:32 PM
  5. Access to Word - Multiple Word Templates?
    By alpinegroove in forum Programming
    Replies: 11
    Last Post: 06-12-2012, 04:42 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums