NewOrderFac33
Well-known Member
- Joined
- Sep 26, 2011
- Messages
- 1,283
- Office Version
- 2016
- 2010
- Platform
- 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:
and here's the code I use to create the new worksheet and import the previously saved JPEG:
Can anyone hep, please?
Thanks in advance
Pete
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: