473,804 Members | 2,132 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.ActiveSh eet.Pictures.In sert("C:\Images \AB1.jpg").Sele ct()

Option Strict disallows late binding and oExcel.Activesh eet 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.Applicati on = New Excel.Applicati on

'Get a new workbook
Dim oBook As Excel.Workbook = CType(oExcel.Wo rkbooks.Add(), Excel.Workbook)
Dim oSheet As Excel.Worksheet = CType(oBook.Act iveSheet, Excel.Worksheet )
Dim oRng As Excel.Range

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

oExcel.ActiveSh eet.Pictures.In sert("C:\Images \AB1.jpg").Sele ct()
oSheet.SaveAs(t empFileName)

'Save the report.
oExcel.Workbook s.Close()
oExcel.Quit()
System.Runtime. InteropServices .Marshal.Releas eComObject(oExc el)

oSheet = Nothing
oBook = Nothing
oExcel = Nothing

Any help would be much appreciated.

Regards
Dec 16 '05 #1
0 5705

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

Similar topics

3
11769
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 table in MySQL with the path & filename to the image. I have successfully uploaded and performed an update query on the database, but the problem I have is I cannot retain the primary key field in a variable which is then used in a SQL update...
22
15360
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 reproduce the behavior described below? For this example, I am using Excel 2002 and VS .NET 2002 and VB 6. MSFT KB article 304661 gives a trivial example of early and late binding to Excel from VB .NET. Note that there is a variable naming...
5
7345
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
3059
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 OpenFileDialog1.ShowDialog() = DialogResult.OK The Dim sr As New System.IO.StreamReader(OpenFileDialog1.FileName Me.BackgroundImage = Image.FromFile(OpenFileDialog1.FileName sr.Close( End I End Su
4
1949
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 DBNull.Value Then b = dsSupp.Tables(0).Rows(0).Item("BITMAP") end if
4
2965
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, thumbSize.Width, thumbSize.Height) imgThumbOutput.Save(Server.MapPath(ThumbnailPath), thisFormat) When I turn on Option Strict, I receive the following compile error: Overload resolution failed because no accessible 'Save' can be called with these...
1
8719
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 6.0. Code: --- use in mainform ------- Option Compare Database Option Explicit
2
8352
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 .... webOCWraooer,Copy // get the desired data into clapboard
3
9992
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 instance. The next time the total would be written to cell A3 and so on. Here is how I create the spreadsheet: oExcel = New Microsoft.Office.Interop.Excel.Application oBook = oExcel.Workbooks.Add oSheet = CType(oBook.Worksheets(1),...
0
9595
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10603
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10356
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10099
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7643
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6869
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5675
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4314
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 we have to send another system
3
3003
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.