Exporting Cell Range As PNG - Getting A White Border To The Bottom & Right - Why?

TkdKidSnake

Active Member
Joined
Nov 27, 2012
Messages
255
Office Version
  1. 365
Platform
  1. Windows
Hi all,

I am exporting a range of cells as a PNG however, when I look at the result I am getting a white border at the bottom and to the right (there isn't any white there) - Any ideas why and how to resolve this as it would save me having to manually edit each time.

The code I have is:

VBA Code:
Sub Xport01Mon()
'
Sheets("Mon").Select
ActiveSheet.Unprotect

Dim ws As Worksheet
Dim table As Range
Dim pic As Picture
Dim cht As ChartObject
Dim myPath As String
Dim myPic As String
Dim myWidth As Long
Dim myHeight As Long

Set ws = ThisWorkbook.Sheets("Mon")
Set table = ws.Range("B5:X548")

myPath = "C:\Users\stevseat\Documents\001 - TST Schedule\"
myPic = Range("C1").Value

table.CopyPicture xlScreen, xlPicture
myWidth = table.Width
myHeight = table.Height

Set cht = ws.ChartObjects.Add(Left:=0, Top:=0, _
    Width:=myWidth, Height:=myHeight)
    
cht.Activate

With cht.Chart
    .Paste
    .Export Filename:=myPath & myPic, Filtername:="png"
End With

cht.Delete

ActiveSheet.Protect

End Sub

This is what I am seeing as the output:

2024 - Wk 48 - 01 - Monday.png


Any help you can provide would be greatly appreciated.

Thanks in advance
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
It looks to me like that is a 3D effect (so the object looks raised with a beveled edge). Have never used that feature. Did you try using a mix of different parameters like bitmap or printer?
 
Upvote 0
Try adding cht.Border.LineStyle = xlLineStyleNone after the cht.Activate line.
Hi, thank your for your input, I've tried this and I'm still getting, I have 7 worksheets all formatted the same most have the borders as described, 1 only has it on the right side - its very strange as they are only tables that I am exporting to PNGs
 
Upvote 0
It looks to me like that is a 3D effect (so the object looks raised with a beveled edge). Have never used that feature. Did you try using a mix of different parameters like bitmap or printer?
Hi,
Thank you for your response, no 3D effects they are just excel standard tables (7 in total one for each day of the week)

Not sure what you mean by "Did you try using a mix of different parameters like bitmap or printer?" as these are saved files and this is how they display on screen.
 
Upvote 0
I don't think you're understanding my meaning. I said the resulting image looks like it is of an area where a 3D effect has been applied to the image. Here are 2 textboxes, the lower one with its "special effect" property set to "raised".
1732577586705.png

I assumed you would know about the parameters used in the CopyPicture method. I've long closed those browser windows so I'll leave it to you to research CopyPicture for now.
 
Upvote 0
I don't use chartobjects anymore.
I prefer the copying to Irfanview and saving from there as a picture
You can copy a selection or a range into Irfanview
 
Upvote 0
I don't think you're understanding my meaning. I said the resulting image looks like it is of an area where a 3D effect has been applied to the image. Here are 2 textboxes, the lower one with its "special effect" property set to "raised".
View attachment 119637
I assumed you would know about the parameters used in the CopyPicture method. I've long closed those browser windows so I'll leave it to you to research CopyPicture for now.
Hi,

I do understand what you are say and no there isn't any 3D formatting applied.
 
Upvote 0
If you want to try by installing IrfanView, it is a very good program and it is free, with all the required plugins.

This is for two computers as you see.
Normally one does not need the Select Case part.

Code:
Sub With_IrfanView()
Dim myPic As Object
Dim cv As String, savePath As String
Set myPic = ActiveSheet.Range("A1:H1")    '<---- Change as required
Select Case Environ("computername")
Case "DESKTOP"
cv = "C:\Program Files\IrfanView\i_view64.exe"
Case "LAPTOP"
cv = "C:\Program Files (x86)\IrfanView\i_view32.exe"
End Select
savePath = "C:\WhatEver Folder\WhatEver Picture Save Name.jpg"    '<---- Change as required
myPic.Copy
Shell cv & " ""/clippaste /convert=" & savePath & """", vbNormalFocus
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,506
Messages
6,179,159
Members
452,892
Latest member
yadavagiri

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