+ Reply to Thread
Results 1 to 3 of 3

Macro to Export from Excel to .jpg

Hybrid View

davo3286 Macro to Export from Excel to... 06-14-2018, 04:49 AM
xlnitwit Re: Macro to Export from... 06-14-2018, 05:27 AM
davo3286 Re: Macro to Export from... 06-14-2018, 06:43 AM
  1. #1
    Forum Contributor
    Join Date
    06-07-2018
    Location
    Newcastle Upon Tyne, England
    MS-Off Ver
    365
    Posts
    143

    Macro to Export from Excel to .jpg

    I have a Macro that works brilliantly to export from Excel to .jpg but I have 2 questions:

    1. Does anyone know what I can add to allow me to chose where the .jpg file saves? At the moment it saves to my computers default location.

    2. Is there a way of making the exported .jpg higher quality?

    Here is the code I currently use:

    Sub ExportLeagueTable()
    
     Dim oWs As Worksheet
     Dim oRng As Range
     Dim oChrtO As ChartObject
     Dim lWidth As Long, lHeight As Long
    
     Set oWs = ActiveSheet
     Set oRng = oWs.Range("A1:P26")
    
     oRng.CopyPicture xlScreen, xlPicture
     lWidth = oRng.Width
     lHeight = oRng.Height
    
     Set oChrtO = oWs.ChartObjects.Add(Left:=0, Top:=0, Width:=lWidth, Height:=lHeight)
    
     oChrtO.Activate
     With oChrtO.Chart
      .Paste
      .Export Filename:="NBL League Table 18.jpg", Filtername:="JPG"
     End With
    
     oChrtO.Delete
    
    End Sub
    Thanks
    Last edited by davo3286; 06-14-2018 at 05:02 AM.

  2. #2
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Macro to Export from Excel to .jpg

    This will allow you to pick a location. I think it's about as good as you'll get with this method and jpg files- if you change the type to BMP, you'd get better quality but a much larger file
    Sub ExportLeagueTable()
    
     Dim oWs As Worksheet
     Dim oRng As Range
     Dim oChrtO As ChartObject
     Dim lWidth As Long, lHeight As Long
     Dim saveFileName As String
    
     Set oWs = ActiveSheet
     Set oRng = oWs.Range("A1:P26")
     
     Const cPICTURE_TYPE As String = "JPG"
    
    saveFileName = Application.GetSaveAsFilename("NBL League Table 18." & cPICTURE_TYPE, cPICTURE_TYPE & " files (*." & cPICTURE_TYPE & "), *." & cPICTURE_TYPE)
    If saveFileName = "False" Then Exit Sub
     oRng.CopyPicture xlScreen, IIf(cPICTURE_TYPE = "BMP", xlBitmap, xlPicture)
     lWidth = oRng.Width
     lHeight = oRng.Height
    
     Set oChrtO = oWs.ChartObjects.Add(Left:=0, Top:=0, Width:=lWidth, Height:=lHeight)
    
     oChrtO.Activate
     With oChrtO.Chart
      .Paste
      .Export Filename:=saveFileName, Filtername:=cPICTURE_TYPE
     End With
    
     oChrtO.Delete
    
    End Sub
    Don
    Please remember to mark your thread 'Solved' when appropriate.

  3. #3
    Forum Contributor
    Join Date
    06-07-2018
    Location
    Newcastle Upon Tyne, England
    MS-Off Ver
    365
    Posts
    143

    Re: Macro to Export from Excel to .jpg

    Much appreciated!... I've given it a go and it's working perfectly!

+ 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. [SOLVED] Data Export Macro works in Excel 2013 but not Excel 2007
    By margentieri in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-27-2016, 10:49 AM
  2. Macro export from excel
    By Human2014 in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 09-18-2015, 01:58 PM
  3. Macro to export from SAP to Excel
    By LeanAccountant in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-12-2015, 05:58 AM
  4. Macro to export excel data as csv
    By senbon in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-08-2014, 10:33 AM
  5. Replies: 0
    Last Post: 02-20-2013, 09:57 AM
  6. I would need a macro to export data from base example workbook to export worbook
    By slato8 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-01-2012, 11:21 AM
  7. Replies: 2
    Last Post: 07-18-2012, 11:17 PM

Tags for this Thread

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