Results 1 to 4 of 4

Thread: [RESOLVED] Exporting Image From Excel

Threaded View

  1. #1

    Thread Starter
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Resolved [RESOLVED] Exporting Image From Excel

    Hello

    This code works in VBA

    http://www.vbforums.com/showthread.php?t=538529

    However, when I try it from vb.net, I get the following error. (Image attached)

    The code that I am trying is as follows

    Code:
    Imports Excel = Microsoft.Office.Interop.Excel
    
    Public Class Form1
        Private Sub Button1_Click(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles Button1.Click
    
            Dim xlApp As Excel.Application
            Dim xlWorkBook As Excel.Workbook
            Dim xlWorkSheet As Excel.Worksheet
            Dim olobj As Excel.Shape
            Dim xlCharts As Excel.ChartObjects
            Dim myChart As Excel.ChartObject
            Dim I As Long = 1
            xlApp = New Excel.ApplicationClass
            xlWorkBook = xlApp.Workbooks.Open("C:\Test.xlsx")
            xlWorkSheet = xlWorkBook.Worksheets("Sheet1")
            xlCharts = xlWorkSheet.ChartObjects
            myChart = xlCharts.Add(10, 80, 300, 250)
    
            '<~~ There could be more pictures than one
            For Each olobj In xlWorkSheet.Shapes
                olobj.Copy()
                myChart.Activate()
                myChart.Paste()
                myChart.Export("C:\Image" & I & ".gif", "FilterName:=GIF", True)
                I = I + 1
                '<~~ code to delete the picture from Chart and make it ready
                '<~~ for next picture
                '<~~(STILL STUCK ON THIS. WILL TACKLE IT AFTER THE ABOVE IS SORTED)
            Next
            xlWorkBook.Close(SaveChanges:=False)
            xlApp.Quit()
    
            releaseObject(xlApp)
            releaseObject(xlWorkBook)
            releaseObject(xlWorkSheet)
        End Sub
    
        Private Sub releaseObject(ByVal obj As Object)
            Try
                System.Runtime.InteropServices.Marshal.ReleaseComObject(obj)
                obj = Nothing
            Catch ex As Exception
                obj = Nothing
            Finally
                GC.Collect()
            End Try
        End Sub
    End Class
    Thanks for looking into it.

    Sid
    Attached Images Attached Images  
    Attached Files Attached Files
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width