473,511 Members | 16,730 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Import an Image into Excel with Option Strict On

Hi,

would anyone be able to point me in the right direction on how to import an
image (.jpg file) into
an Excel worksheet using VB.Net and Option Strict On. This should be
straight forward however with Excel returning some weak-typed objects we are
having problems.

The only problem we have is with line (full code below)
oExcel.ActiveSheet.Pictures.Insert("C:\Images\AB1. jpg").Select()

Option Strict disallows late binding and oExcel.Activesheet returns an
Object Type of Object

With Option Strict off the following code works fine:

'Start Excel and get Application object
Dim oExcel As Excel.Application = New Excel.Application

'Get a new workbook
Dim oBook As Excel.Workbook = CType(oExcel.Workbooks.Add(), Excel.Workbook)
Dim oSheet As Excel.Worksheet = CType(oBook.ActiveSheet, Excel.Worksheet)
Dim oRng As Excel.Range

With oSheet
CType(.Cells(4, 1), Excel.Range).Value = "COMPILED:-"
CType(.Cells(5, 1), Excel.Range).Value = "TITLE:-"
CType(.Cells(6, 1), Excel.Range).Value = "APPROVED"
CType(.Cells(27, 2), Excel.Range).Value = "PIC ID"
CType(.Cells(24, 8), Excel.Range).Value = "PIC ID"
CType(.Cells(45, 7), Excel.Range).Value = "PIC ID"
oRng = DirectCast(.Cells(5, 5), Excel.Range)
oRng.Cells.Select()
End With

oExcel.ActiveSheet.Pictures.Insert("C:\Images\AB1. jpg").Select()
oSheet.SaveAs(tempFileName)

'Save the report.
oExcel.Workbooks.Close()
oExcel.Quit()
System.Runtime.InteropServices.Marshal.ReleaseComO bject(oExcel)

oSheet = Nothing
oBook = Nothing
oExcel = Nothing

Any help would be much appreciated.

Regards
Dec 16 '05 #1
0 5676

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
11737
by: dave | last post by:
Hello there, I am at my wit's end ! I have used the following script succesfully to upload an image to my web space. But what I really want to be able to do is to update an existing record in a...
22
15312
by: Howard Kaikow | last post by:
There's a significant problem in automating Excel from VB .NET. Reminds me of a problem I encountered almost 3 years ago that was caused by the Norton Auntie Virus Office plug-in. Can anybody...
5
7330
by: touf | last post by:
Hi, I've an error when I declare Dim oBook As Excel.Workbooks What imports, and reference do I need to use Excel.Workbooks class? Thanks
39
3010
by: jcrouse | last post by:
I am using the following code to get a background image for my form Private Sub mnuBgroundImage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuBgroundImage.Clic If...
4
1930
by: Piedro | last post by:
Hi group, how do I read a image/blob field in cas option strict is on? First I had it turned off and I read it like this: Dim b() As Byte If Not dsSupp.Tables(0).Rows(0).Item("BITMAP") Is...
4
2950
by: jmhmaine | last post by:
The following code works when Option Strict is off: Dim thumbSize As New Size thumbSize = CType(NewthumbSize(g.Width, g.Height, 100), System.Drawing.Size) Dim imgThumbOutput As New Bitmap(g,...
1
8694
by: baling | last post by:
Hi.... Hi everybody, i have a code that i make in VBA and know I want to use this code in to VB6. But i don't know how to use that code in to VB 6.0 Please correct this code so i can use it in VB...
2
8326
by: GS | last post by:
I have installed the ms PIA for ofc XP, and followed the article http://support.microsoft.com/kb/247412/ trying to paste into a worksheet However I got late binding not allowed errors .......
3
9977
by: spowel4 | last post by:
I need some help with this please: I'm looping through some data to total some figures. Each time the total is calculated I need to insert that total into an excel spreadsheet cell, A2 for...
0
7242
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7353
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7418
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7508
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4737
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3222
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3212
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1572
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
781
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.