![]() |
|
||||||||
| Site Links |
| Consulting |
| Knowledge Base |
| Training |
| Forum |
| Articles |
| Resources |
| Products |
| Cool Tools |
| Contact |
| About Us |
| Go to Page... |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
|
Solved: Bitmaps with Excel VBA, how to create
Hi folks,
How does one create a bitmap file with Excel VBA? All I need is the very basics, like how to create a file that is, for example, 100 pixels tall and 200 pixels wide, with a blue triangle and white background, or anything remotely like that. Thanks, yet again, in advance. - Ray |
|
Local Time: 03:36 AM
Local Date: 05-25-2013 Location:
|
|
|
|
#2 |
|
Administrator
|
Do you need the code, or just the functionality? I haven't tried this myself, but you may want to look at this:
"Create Bitmap from Selection" Ken Puls, CMA - Microsoft MVP (Excel) I hate it when my computer does what I tell it to, and not what I want it to. Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here! Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved! ![]() |
|
Local Time: 03:36 AM
Local Date: 05-25-2013 Location:
|
|
|
|
#3 |
|
|
Hi Ken,
I tried it and my opinion is; this add-in is very useful. Thank you very much. ![]() Erdin? E. Kara?am | Loves from Bursa city in Republic of T?rkiye |
|
Local Time: 12:36 PM
Local Date: 05-25-2013 Location:
|
|
|
|
#4 |
|
Administrator
Chat VP |
Also, Excel (well xl2000+ anyway) has a built-in camera function, here's some very old code I have that gives an example usage for you to play with...
VBA:
VBA tags courtesy of www.thecodenet.com
(edited) You know you're really in trouble when the light at the end of the tunnel turns out to be the headlight of a train hurtling towards you The major part of getting the right answer lies in asking the right question... ![]() Made your code more readable, use VBA tags (this automatically inserts [vba] at the start of your code, and [/vba ] at the end of your code) | Help those helping you by marking your thread solved when it is. |
|
Local Time: 08:36 PM
Local Date: 05-25-2013 Location:
|
|
|
|
#5 |
|
Administrator
Chat VP |
Here's some more ideas you can play with...
The picture tool can be found in View > Toolbars > customize > tools (it has a picture of a camera on it) - drag it and put it on a toolbar somewhere. Now (you can record all this if you like) Select a range - the range can include shapes, pictures (whatever) and click the camera tool. Your mouse icon is now a cross, put the cross anywhere on the sheet (or another sheet {this can also be in another workbook}) left-click and drag the mouse icon. You'll now see a picture there, and in the formula bar you'll see the address of the selected range - this is because the picture is now linked to your original range. Any changes you now make (including any changes to shapes, cell formatting, etc) in the original range will show in this linked picture, and, if you change the range link in the formula bar, you'll get a new picture of this other range. This allows you create a "window" (or any number of them) that allows you to view changes on other worksheets when changes are made to the active sheet. Another 'bonus' is that double-clicking the picture will activate the sheet and select the range it's linked to (and if the picture is linked to a closed book it will open that book) To make an unlinked picture - select a range as before, hold down Shift, go to Edit and select Copy Picture - you'll get a dialog box offering a choice of Picture or Bitmap - press OK and let go of Shift. Select the range where you want your picture, hold down Shift, go to Edit again and select Paste Picture (n.b. those options are only available while holding down Shift). Note that you can also format the picture if you like... Have a read here to read about some practical uses for linked pictures. HTH ![]() (edited) You know you're really in trouble when the light at the end of the tunnel turns out to be the headlight of a train hurtling towards you The major part of getting the right answer lies in asking the right question... ![]() Made your code more readable, use VBA tags (this automatically inserts [vba] at the start of your code, and [/vba ] at the end of your code) | Help those helping you by marking your thread solved when it is. |
|
Local Time: 08:36 PM
Local Date: 05-25-2013 Location:
|
|
|
|
#6 |
|
Distinguished Lord of VBAX
|
Sound slike the guy wants Excel to be a paint type program.
|
|
Local Time: 11:36 AM
Local Date: 05-25-2013 Location:
|
|
|
|
#7 |
|
|
I see that this is 'solved', but perhaps someone will be interested in a more versatile solution.
See my blog. zababcdblog.blogspot.com/2012/01/how-to-write-bmp-file-from-excel-vba.html And zababcdblog.blogspot.com/2012/01/how-to-write-bmp-file-from-excel-vba-2.html It's actually very simple to write it directly as bytes, once you know the bitmap file structure. The second link is a slight improvement on the first so that you don't need to read from a file. The blue triangle on a white background (for example), would be written like this: For x = 1 To ImgHeight For y = 1 To ImgWidth If y <= (ImgWidth + 1)/2 Then 'Left half of the picture, 'including middle column if any If x >= 2*y/(ImgWidth + 1) Then 'If the row is below or at 'the percentage of height that the column is of halfway ImageColours(x, y, 1) = 0 'no red ImageColours(x, y, 2) = 0 'no green ImageColours(x, y, 3) = 255 'all blue Else For z = 1 to 3 ImageColours(x, y, z) = 255 'all colours = white Next z End If Else 'if it's on the right side of the image, then the left For z = 1 to 3 'is already done so just reflect the image ImageColours(x, y, z) = ImageColours(x, ImgWidth - y + 1, z) Next z End If Next y Next x |
|
Local Time: 09:36 PM
Local Date: 05-25-2013 Location:
|
|
|
|
#8 |
|
|
I'm glad to learn of an elaborate solution to this problem.
|
|
Local Time: 02:36 AM
Local Date: 05-25-2013 Location:
|
|
![]() |
| Display Modes |
Linear Mode |
Switch to Hybrid Mode |
Switch to Threaded Mode |
|
|


