Ich möchte einen markierten Excelbereich als Jpg exportieren.
Mein Makro funktioniert soweit ganz gut, allerdings versuche ich , den Auswahlbereich über eine Inputbox anzusprechen.
Und hier hakt es. Irgendwie scheine ich bei der Inputbox etwas zu übersehen oder anders falsch zu machen.
Vielleicht hat hier im Forum wer eine Idee, das richtig zu stellen (fett die von mir eingefügte Input box, bzw, mein Versuch)
Sub SelectedRangeToImage()
Dim tmpChart As Chart, n As Long, shCount As Long, sht As Worksheet, sh As Shape
Dim fileSaveName As Variant, pic As Variant
Dim DataRange As Range
'Create temporary chart as canvas
Set sht = Selection.Worksheet
Set DataRange = Application.InputBox(Title:="Select your range", Prompt:="Select the _
range of dates", Default:=ThisWorkbook.Range("D14:U42").Address, Type:=8)
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
fileSaveName = Application.GetSaveAsFilename(FileFilter:="Image (*.jpg), *.jpg")
If fileSaveName False Then
tmpChart.EXPORT FileName:=fileSaveName, FilterName:="jpg"
End If
'Clean up
sht.Cells(1, 1).Activate
sht.ChartObjects(sht.ChartObjects.Count).Delete
sh.Delete
End Sub