0

I'm in an excel vba program and I need to display and create a label for a printer.

Now this printer (Zebra Z4M Plus 300 dpi) is extremely fussy and hard to use. I can now print to it if I create an image file (png or img) of dimensions 944x406 and put my desired label in an area of 797x396 in the upper left corner of that image file.

My question is about creating said image.

Some 10 years ago I remember that it was possible (in probably vb6) to use image primitives such as lines, polygons, circles and text to a picturebox control.

In Excel I have created a form and created an image control however a look at the functions and properties of this object didn't reveal any function for drawing anything on it !

(P.S. I have now found that this image object has a .picture property, this property has a .handle property and .render function, I must be close to something usable but I can't find it. It seems I could load a picture from a picture file using the LoadPicture function on this picture property)

(Perhaps there are windows api function that will let me draw on this .picture using the .picture.handle ?)

The excel Shape object also didn't have drawing primitives but it did have a .CopyPicture function that would allow me to put the contained image in the clipboard (and then I just need to find a way to save the clipboard content to an image file)

If possible I would like to draw to an object which is contained in the worksheet rather than in a userform.

I am looking for further search keywords, names of objects and function for drawing.

Thank you !

Shodan
  • 1,065
  • 2
  • 13
  • 35
  • Not clear what you are looking for, but maybe this will point out something for you ... Record a macro: Step 1- use the drawing shapes to make a small diagram. Step 2- select all of the shapes and copy. Step3- PasteSpecial and select the as PNG option. Stop macro recording. Check out the macro code for pointers. ... This is all contained in the worksheet. – OldUgly May 04 '16 at 23:17
  • Possible duplicate of http://stackoverflow.com/questions/18232987/export-pictures-from-excel-file-into-jpg-using-vba and http://stackoverflow.com/questions/25333558/export-pictures-excel-vba – PatricK May 05 '16 at 05:14
  • Thanks @Patrick, the link you provided gave me the Chart object as a picture surface that can be saved to an image file using the .Chart.Export function. Now I just need to find out how to draw (using vba) lines,polygons and text on it. – Shodan May 06 '16 at 19:56
  • I suppose you can try with the Chart object, `.Shapes.AddTextbox` or something. See [MSDN Shapes](https://msdn.microsoft.com/en-us/library/office/ff841018(v=office.14).aspx) – PatricK May 08 '16 at 23:26
  • Hi, Patrick, I've been using the chart object as you suggested. It has been great ! I'm even using .Chart.PrintOut to print directly to my sticker printer. I dynamically add textboxes/shapes and image to it and reshape to match the aspect ration of the stickers. The user can even fine tune the positioning before printing. So much easier than using a GDI drawing surface ! – Shodan Jul 31 '16 at 13:41

0 Answers0