Chart picture vs camera tool - Which to use?

Mr_Ragweed2

Board Regular
Joined
Nov 11, 2022
Messages
145
Office Version
  1. 365
Platform
  1. Windows
Hello all! I have been reading posts here and online and i'm not sure which path to try. I have a Userform with many buttons that lead to various "Orderforms" - 1 per vendor. What my macro does is capture the info from each vendor onto 1 "Summary" Sheet and 1 "customer info" sheet. (I guess i could technically combine the data into 1 sheet behind the scenes.) What i would like to do is put the data from both of those sheets back onto the userform when the user is finished, and then make the userform printable. I have set aside space on the form to house this. Which is better/easier (I redefine novice every time i use VBA), chart picture or camera tool? Will i be able to "choose" where i place it on the userform?
I will happily share some code and/or screenshots of the Userform - just didn't want to waste anyone's time if this is not even possible.
Even if there is no help here, but you're aware of something you've seen - all help is greatly appreciated.

Total width of data is 12 columns and total number of rows (including headers and blank rows) is dynamic from 8 to 21. So not a large table/chart/picture.
I'm on Windows 10, Office 365
Thank you very much!
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
If you select ctrl-alt-prt sc (control alt and printscreen) (if I remember right) you can get a picure copy of the entire userform. I don't think there's any way to get just a portion of it? I assume that the code at the following link is using this approach to change the keypress event from a copy to an image file, but it seems like a lot of messing around. Much better just to set up an area of a worksheet and use that to create an image file. There are a couple of approaches for this such as copying the area to a chart and exporting as an image file or by using some API code to generate an image file. HTH. Dave
 
Upvote 0
NdNoviceHlp, Thank you for your reply. That helps a lot with printing the userform.

What about putting two images onto the userform from a spreadsheet? Is that a thing? The data is basically a small table. Would populating it to a listbox or something be simpler? It's basically an invoice app i'm creating.
 
Upvote 0
You can put 2 images on a userform by placing 2 container objects on the form. ie. 2 image controls. Copy the range of your table, paste it to a chart, export it as an image file, then load the image to your image control. HTH. Dave
 
Upvote 0
Yes. I'm working on it still. Hope to finish today. Will post results regardless of outcome.
 
Upvote 0
This should work for you. Adjust userform name and image control name to suit. HTH. Dave
Code:
Public Sub CreateJpg(SheetName As String, xRgAddrss As Range)
'Userform code ****adjust Userform1 & Image1 to suit
'creates temp JPG file of range (xRgAddrss) by creating temp chart
'uses current wb sheet (sheetname) to locate temp chart
'To operate:  Call CreateJpg("Sheet1", Sheets("Sheet1").Range("A1:H8"))
'adjust sheet name and range to suit
Dim xRgPic As Range
Worksheets(SheetName).Activate
Set xRgPic = xRgAddrss
xRgPic.CopyPicture
With ThisWorkbook.Worksheets(SheetName).ChartObjects.Add(UserForm1.Image1.Left, _
                UserForm1.Image1.Top, UserForm1.Image1.Width, UserForm1.Image1.Height)
.Activate
.Chart.Paste
.Chart.Export Environ$("temp") & "" & "TempChart.jpg", "JPG"
End With
Worksheets(SheetName).ChartObjects(Worksheets(SheetName).ChartObjects.Count).Delete
UserForm1.Image1.Picture = LoadPicture(Environ$("temp") & "" & "TempChart.jpg")
Kill Environ$("temp") & "" & "TempChart.jpg"
End Sub
 
Upvote 0
ok I adjusted names in the code and am getting an error at the xRgPic.CopyPicture line. Code posted below:

VBA Code:
Sub put_pic_on_userform()
'completely taken from above - just changed names of sheets, etc

Dim xRgAddress As Range
Dim xRgPic As Range
Worksheets("Combined data").Activate
Set xRgPic = xRgAddress
xRgPic.CopyPicture   'Error here: "Object variable or With block variable not set"

With ThisWorkbook.Worksheets("Combined data").ChartObjects.Add(UserForm1_MasterSeedOrderForm.Image3.Left, _
            UserForm1_MasterSeedOrderForm.Image3.Top, UserForm1_MasterSeedOrderForm.Image3.Width, UserForm1.Image3.Height)
.Activate
.Chart.Paste
.Chart.Export Environ$("temp") & "" & "TempChart.jpeg", "JPG"
End With
Worksheets("Combined data").ChartObjects(Worksheets("Combined data").ChartObjects.Count).Delete
UserForm1_MasterSeedOrderForm.Image3.Picture = LoadPicture(Environ$("temp") & "" & "TempChart.jpg")
Kill Environ$("temp") & "" & "TempChart.jpg"

End Sub
 
Upvote 0
I am not seeing where i tell it what to copy - ie) size of range? It is a bit different than originally posted. It is columns A thru L but the number of rows is dynamic. SO sorry if i didnt relay that earlier. my apologies
 
Upvote 0

Forum statistics

Threads
1,215,425
Messages
6,124,824
Members
449,190
Latest member
rscraig11

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