Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Import an Image into Excel using VB.Net and 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



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Import an Image into Excel using VB.Net and Option Strict On

Jedawi,
I am no .Net expert, but as ActiveSheet could in theory be a worksheet,
chart or macro, it has to evaluate to an "Object".
Does
oSheet.Pictures.Insert("C:\Images\AB1.jpg").Select ()
work ?

NickHK

"Jedawi" wrote in message
...
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





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Import Crystal report with an image Import from Crystal reports with image Setting up and Configuration of Excel 0 May 11th 10 05:40 PM
Can i use the IF condition to import an image or change a cell col martin59 Excel Worksheet Functions 3 August 10th 08 11:02 AM
Macro Image Import Size Issue Ben-8151 Excel Discussion (Misc queries) 0 July 11th 08 02:48 PM
How do I sort in strict numerical order? i.e. 105 before 1049 mgr Excel Discussion (Misc queries) 1 June 14th 06 05:19 PM
How to import multiple image files into spreadsheet wraithlead[_5_] Excel Programming 1 October 12th 04 07:54 PM


All times are GMT +1. The time now is 05:31 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"