I am having a lot of trouble understanding how Excel works with the newer .NET language. Slowly buy surely I am figuring this out... with the help of everyone on VB Forums.
Thank you in advance for your time and assistance.
It took a lot of searching but here it is.
Also at the bottom is getting rid of GridLines in the display if anyone needs that code.
VB Code:
Dim oXL As Excel.Application
Dim oWB As Excel.Workbook
Dim oSheet As Excel.Worksheet
' Start Excel and get Application object.
oXL = CreateObject("Excel.Application")
oWB = oXL.Workbooks.Add
oSheet = oWB.ActiveSheet
oSheet.Visible = True
Dim pic As String = System.Windows.Forms.Application.StartupPath & "/logos/logo1.bmp"
oSheet.Range("B1:B1").Select() 'This is where the top left corner of picture will be
Dim opicture As Object
opicture = oSheet.Pictures.Insert(pic)
opicture.ShapeRange.ScaleWidth(0.5, 0, 0)
opicture.ShapeRange.ScaleHeight(0.5, 0, 0)
GridLines not Visible
VB Code:
oXL.ActiveWindow.DisplayGridlines = False
Finally, the reason for using
VB Code:
System.Windows.Forms.Application.StartupPath
and not
VB Code:
Application.StartupPath
as suggested is that 'Application' is ambiguous, imported from the namespaces or types 'CRAXDDRT, System.Windows.Forms'.
Because I am using Crystal Reports - the namespace was conflicting and I had to fully qualify it.
Hope this helps someone who may be struggling with this.
Last edited by craigreilly; Jun 2nd, 2006 at 06:50 PM.
Re: [RESOLVED] Resizing picture in Excel from VB.NET
Yes, when importing other namespaces that have an Application object, like Word and CR, you need to qualify them to make each one distinctly different and recognizable by .net.
I never import all the way down to Word but just to the .Interop class. Then each will be identifiable.
VB Code:
Imports Microsoft.Office.Interop
'...
Word.Application....
Outlook.Application....
'And
'VS
Application.StartupPath
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Re: [RESOLVED] Resizing picture in Excel from VB.NET
I am not quite sure how to do what you are suggesting. In VB.NET 2005, I goto the 'Project Properties', click on References, and select the Namespaces to import.
So, I think in my case, I had to fully qualify the Application.StartupPath to System.Windows.Forms.Application.StartupPath - I did not see a choice in the matter.
Thanks for any additional info you may have in helping my understand this.
Last edited by craigreilly; Jun 3rd, 2006 at 10:41 AM.
Re: [RESOLVED] Resizing picture in Excel from VB.NET
Is is rather strange - a little change from the 03 days.
The Designer generated code is hidden by default. In the solution explorer you have to 'Show All Filed' then expand your form and double click on the Form.Designer.vb file.
Re: [RESOLVED] Resizing picture in Excel from VB.NET
I think there is still another part to it. There is supossed to be a partial class file that sontains all the code for creating the controls and events. It should be in there.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Re: [RESOLVED] Resizing picture in Excel from VB.NET
As I mentioned in my previous, you can show all files and see the .resx. I think the info is in here... But - playing in here can lead to some serious problems. I'd rather stay out.