I have a routine whereby Excel creates a chart which is then loaded into the PictureBox of a Form.
The PictureBox.Image is firstly Disposed. Excel is called. Excel then Exports the image of the Chart to a .PNG File. And my routine places this .PNG file into the PictureBox.
My problem is that this only works ONCE.
If I call the same routine again, the PictureBox displays not the .PNG file, but the ErrorImage.
Now, this worked fine using VB Express on a Vista machine.
But on a Win7 machine using Visual Studio 10, the routine can only be passed through successfully ONCE.
Here is a summary of my code ...
If Me.PictureBox1.Image IsNot Nothing Then Me.PictureBox1.Image.Dispose()
If My.Computer.FileSystem.FileExists("TheImage.png") Then
xl.Visible = False
XLWorkBooks = xl.Workbooks()
XLWorkBook = XLWorkBooks.Open("C:\oldf\MYEXCEL\progresschart.xlsm")
Dim XLChart = XLWorkBook.ActiveChart
PictureBox1.Image = New System.Drawing.Bitmap("TheImage.png")
The file "TheImage.png" is successfully created by Excel every time.
But, as i mentioned above, the PictureBox just will not reload it on the second time round.