Hello All,
I am creating a new script with all kind of examples from the web, because I am a beginner in VBA, but I can't get it right.
Case: Every day I have to create two files from my excel planning sheet, which I save as image on the network. It works now with a hardcopy name, but as I need to copy every day I want to use a cell as part of the filename. This is the script with the hardcoded filename (donderdag 1.jpg) which is working:
Sub Selectie1()
'
' Selectie1 Macro
'
'
Range("B4:U27").Select
Dim tmpChart As Chart, n As Long, shCount As Long, sht As Worksheet, sh As Shape
Dim fileSaveName As Variant, pic As Variant
'Create temporary chart as canvas
Set sht = Selection.Worksheet
Selection.Copy
sht.Pictures.Paste.Select
Set sh = sht.Shapes(sht.Shapes.Count)
Set tmpChart = Charts.Add
tmpChart.ChartArea.Clear
tmpChart.Name = "PicChart" & (Rnd() * 10000)
Set tmpChart = tmpChart.Location(Where:=xlLocationAsObject, Name:=sht.Name)
tmpChart.ChartArea.Width = sh.Width
tmpChart.ChartArea.Height = sh.Height
tmpChart.Parent.Border.LineStyle = 0
'Paste range as image to chart
sh.Copy
tmpChart.ChartArea.Select
tmpChart.Paste
'Save chart image to file
tmpChart.Export FileName:="P:\Planningen\Voor scherm\Donderdag 1.jpg", FilterName:="jpg"
'Clean up
sht.Cells(1, 1).Activate
sht.ChartObjects(sht.ChartObjects.Count).Delete
sh.Delete
End Sub
I want to change Donderdag with the information from cell G4 from the current selected worksheet. So export should be something like:
'Save chart image to file
tmpChart.Export FileName:="P:\Planningen\Voor scherm\(g4)-1.jpg", FilterName:="jpg"
'Clean up
Any help would be appreciated very much!
Kind regards,
Joost
Bookmarks