Avatar of Jimbo99999
Jimbo99999
Flag for United States of America asked on

VB.Net - Excel Automation Add Chceckbox to Cell

Good Day Experts!

I have been tasked with automating Excel from my VB.net project to display report data from a VB.net form.  The report is a evry simple layout.  I have column headings that I need to indicate yes or no in the cell under each of them.  

I could just add test yes or no but I thought adding a checkbox with it being checked or unchecked to indicate yes or no would look nicer.  

While I have come across pieces here and htere in my search, I have been able to figure out how t do this.

Can you assist with adding a checkbox to a cell from VB.net?

Thanks,
jimbo99999
Visual Basic.NETMicrosoft Excel

Avatar of undefined
Last Comment
Jimbo99999

8/22/2022 - Mon
SOLUTION
Nasir Razzaq

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Jimbo99999

ASKER
That is a novel idea...excellent.  Yes, I have noticed that the information I have been finding on adding checkboxes does not appear to be very straightforward.  

I will try the two images here now.
Jimbo99999

ASKER
Ok, I am struggling a bit here.  I have the checkmrk.ico getting to the cell with the following code.  However, I am unable to figure out how to center the picture in the cell.

            Dim AppPath As String
            AppPath = "C:\Documents and Settings\User\My Documents\Visual Studio 2005\Projects\VelocityViewer\VelocityViewer"
            AppPath = AppPath + "\" + "CHECKMRK.ico"
            oRng = oSheet.Range("A4", "A4")
            System.Windows.Forms.Clipboard.SetDataObject(Image.FromFile(AppPath), True)
            oSheet.Paste(oRng, Image.FromFile(AppPath))
            System.Windows.Forms.Clipboard.Clear()

Is it possible?

Thanks,
jimbo99999
Nasir Razzaq

I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
Jimbo99999

ASKER
Valiant effort with the centering of the checkbox image and to no avail.  I have the following code:

            With oSheet.Range("A4", "H4")
                .Font.Size = 10
                .Font.Name = "Segoe UI"
                .HorizontalAlignment = Excel.XlVAlign.xlVAlignCenter
            End With

So, I coded Yes or No to be sent to the cell instead of the image.  Yes or no was able to be centered by the above code.

Perhaps the image can't be centered?

Thanks,
jimbo99999
Jimbo99999

ASKER
With a little more detective work, I have found that the cells are actually getting the centering applied based on the toolbar centering icon after I select the cell.  So, for some reason the image is not getting centered...but I don't know why or how to fix.

Thanks,
jimbo99999
ASKER CERTIFIED SOLUTION
Norie

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Jimbo99999

ASKER
Thanks for the responses.  The Marlett format works great...I have my checkmark now.
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.