Issue inserting JPEG containing into Workbook

NewOrderFac33

Well-known Member
Joined
Sep 26, 2011
Messages
1,283
Office Version
  1. 2016
  2. 2010
Platform
  1. Windows
Good afternoon,
I have an area of my worksheet containing pie charts that I export to a JPEG at different points in the week - the idea being that I'm taking a "snapshot" of the piecharts at different points in time, to allow me to compare them over a period.
The code creates a new worksheet, exports the range to a JPEG, then inserts the JPEG to the new worksheet.
This all works fine, except when I close the workbook and re-open it, at which point all the JPEGs in the inserted change to the most recent one.
It's as though there is a hyperlink between each JPEG and the most recently created version of it on disk, but I can't find anything.
Here's the code I uses to create the JPEG:
Code:
Sub Create_JPEG_TM_04()
    Sheets("MySheet").Activate
    Application.GoTo Reference:="TM_04"
    vFilePath1 = "J:\MyPic"
    SlideErrorMessage = "Sorry - I couldn't create the TM_04 JPEG - Please try again!"
    Range("TM_04").Select
    Create_JPEG
End Sub


Sub Create_JPEG()
    'Procedure exports selected range to JPEG file
    'Default filename is WorkbookName+SheetName+RangeAddress.JPG
 
    If TypeName(Selection) <> "Range" Then
        MsgBox "Selection is not a range of cells."
        Exit Sub
    End If
    
    'On Error GoTo ExportError
    
    CurrentSheetName = ActiveSheet.Name
    'Sheets("Stats").Activate
    CurrentZoom = ActiveWindow.Zoom
    ActiveWindow.Zoom = 200
    
    ChDrive ("J:")
    ChDir ("J:\Build and Release\Management\BRMgtPresPack\")
    vFilePath2 = vFilePath1 & ".jpg"
    
    With Selection
       
       'Make picture of selection and copy to clipboard
       .CopyPicture Appearance:=xlScreen, Format:=xlBitmap
   
       'Create an empty chart with exact size of range copied
        With ActiveSheet.ChartObjects.Add( _
            Left:=.Left, Top:=.Top, Width:=.Width, Height:=.Height)
            .Name = "TempChart"
            .Activate
        End With
    
    End With
 
    'Paste into chart area, export to file, delete chart.
    ActiveChart.Paste
    
    With ActiveSheet.ChartObjects("TempChart")
        .Chart.Export CStr(vFilePath2)
        .Delete
    End With
    
    ActiveWindow.Zoom = CurrentZoom
    ActiveWindow.DisplayZeros = False
    Sheets(CurrentSheetName).Activate
    Exit Sub
    
ExportError:
    MsgBox (SlideErrorMessage)
    ActiveWindow.Zoom = CurrentZoom
    Sheets(CurrentSheetName).Activate


End Sub

and here's the code I use to create the new worksheet and import the previously saved JPEG:

Code:
Sub ImportArchive()
    Sheets.Add After:=Sheets(Sheets.Count)
    MySheetName = Format(Now(), "ddd dd-mmm-yy hh-mm")
    ActiveSheet.Name = MySheetName
    ActiveWindow.DisplayGridlines = False
    Range("A1").Select
    Selection.Value = Now()
    With Selection.Font
        .Name = "Arial"
        .Size = 16
        .Bold = True
    End With
    Selection.NumberFormat = "ddd dd-mm-yyyy hh:mm"
    Application.GoTo Reference:="R2C1"
    ActiveSheet.Pictures.Insert("J:\MyPic").Select
End Sub

Can anyone hep, please?
Thanks in advance
Pete
 
Last edited:

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!

Forum statistics

Threads
1,224,823
Messages
6,181,182
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top