Copy of screen shot to sent to email is chopping off the last few columns

JannetteChristie

Board Regular
Joined
Dec 14, 2015
Messages
127
Office Version
  1. 365
Hello,
I have the following sheet that when the user saves it then copies to an email but it is cutting off the last few columns.
The VB code I am using is as follows:
VBA Code:
Sub CreatePNG(Namesheet As String, nameRange As String, nameFile As String)
    'ThisWorkbook.Activate
    'Worksheets(Namesheet).Activate
    Dim Plage As Range
    Set Plage = ThisWorkbook.Worksheets("Report").Range(nameRange)
    Plage.CopyPicture
    With ThisWorkbook.Worksheets(Namesheet).ChartObjects.Add(Plage.Left, Plage.Top, Plage.Width, Plage.Height)
        .Activate
        .Chart.Paste
        .Chart.Export nameFile, "JPG"
    End With
    Worksheets(Namesheet).ChartObjects(Worksheets(Namesheet).ChartObjects.Count).Delete
Set Plage = Nothing
Worksheets("Report").Activate
End Sub

The report

1729103625180.png


When it copies to the email columns S to to V are missing, can anyone advise what I can do to prevent this from happening.

Thanks
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Could you try updating your VBA code like this and see if it works?

VBA Code:
Sub CreatePNG(Namesheet As String, nameRange As String, nameFile As String)
    Dim Plage As Range
    Dim tempSheet As Worksheet
    Dim myPic As Shape
    Dim FileFormat As String
    
    FileFormat = "JPG"
    
    Set Plage = ThisWorkbook.Worksheets("Report").Range(nameRange)
    
    Plage.CopyPicture xlScreen, xlPicture
    
    Set tempSheet = ThisWorkbook.Worksheets.Add
    
    tempSheet.Paste
    
    Set myPic = tempSheet.Shapes(tempSheet.Shapes.Count)
    
    myPic.Left = 0
    myPic.Top = 0
    
    myPic.Export Filename:=nameFile, FilterName:=FileFormat
    
    Application.DisplayAlerts = False
    tempSheet.Delete
    Application.DisplayAlerts = True
    
    Set Plage = Nothing
    Set myPic = Nothing
    Set tempSheet = Nothing
End Sub
 
Upvote 0
Pardon me for squeezing in here ... How does one call that sub "CreatePNG" from a command button ?
Since the macro name as parameters ... I'm at a loss.
 
Upvote 0
Could you try updating your VBA code like this and see if it works?

VBA Code:
Sub CreatePNG(Namesheet As String, nameRange As String, nameFile As String)
    Dim Plage As Range
    Dim tempSheet As Worksheet
    Dim myPic As Shape
    Dim FileFormat As String
   
    FileFormat = "JPG"
   
    Set Plage = ThisWorkbook.Worksheets("Report").Range(nameRange)
   
    Plage.CopyPicture xlScreen, xlPicture
   
    Set tempSheet = ThisWorkbook.Worksheets.Add
   
    tempSheet.Paste
   
    Set myPic = tempSheet.Shapes(tempSheet.Shapes.Count)
   
    myPic.Left = 0
    myPic.Top = 0
   
    myPic.Export Filename:=nameFile, FilterName:=FileFormat
   
    Application.DisplayAlerts = False
    tempSheet.Delete
    Application.DisplayAlerts = True
   
    Set Plage = Nothing
    Set myPic = Nothing
    Set tempSheet = Nothing
End Sub
Hi @pitchoute
Thanks for your response, I am getting an error on the following line:
myPic.Export Filename:=nameFile, FilterName:=FileFormat


I am not able to resolve this.

1729154557654.png
 
Upvote 0
Further update to this,

When the JPG file is automatically added to the file it send it all squashed together.
If I open an email and manually add the JPG to the body of the email there is no issue.

I am struggling to wok out what the issue is here - is there any help available please ?
 
Upvote 0

Forum statistics

Threads
1,223,948
Messages
6,175,571
Members
452,652
Latest member
eduedu

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