• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 432
  • Last Modified:

VBA, picture object

Hello-- I have the attached code that's working fine on my computer but for some reason is crashing on someone else's w/ a "Type Mismatch" error at the "Set PicTemp = Selection" line... why would this be?

Thanks.
 
Public Sub GenerateGIF(sheet1, range1, control1, DataRange)

Sheets(sheet1).Activate
Sheets(sheet1).Range(range1).Select
Selection.Copy

Const FName As String = [directory is here]\temp.gif"

Dim pic_rng As Range
Dim ShTemp As Worksheet
Dim ChTemp As Chart
Dim PicTemp As Picture
Application.ScreenUpdating = False
Set pic_rng = Worksheets(sheet1).Range(range1)
Set ShTemp = Worksheets.Add
Charts.Add
ActiveChart.Location Where:=xlLocationAsObject, Name:=ShTemp.Name

ActiveChart.ChartArea.Select
ActiveSheet.Shapes("Chart 1").ScaleWidth 8, msoFalse, _
    msoScaleFromBottomRight
ActiveSheet.Shapes("Chart 1").ScaleHeight 2, msoFalse, _
    msoScaleFromBottomRight
Set ChTemp = ActiveChart
pic_rng.CopyPicture Appearance:=xlScreen, Format:=xlPicture

ChTemp.Paste
Set PicTemp = Selection

Open in new window

0
Jeff9687
Asked:
Jeff9687
  • 4
  • 2
1 Solution
 
sshah254Commented:
That machine most likely does not have the "Picture" object ... wherever that is coming from.

Check the "Add-ins" on your computer and compare them to the ones on the computer that this program is crashing on.

Ss
0
 
wellousCommented:
try to ignore this crash and continue to see if the rest of works or not.
add this to yr code and see.

on error resume next

Brgds
Wellous
0
 
Jeff9687Author Commented:
The issue seems to be that I built the application in Excel 2003 that has Microsoft Excel 11.0 Object Library in VBA references, and it's crashing in Excel 2007 that's using Microsoft Excel 12.0 Object Library... that's literally the only difference... the Excel version and all the other add-in's and VBA references are the same. Any idea why the Picture object would be working with the 11.0 object library and not 12.0, or how to get this to work?

btw i'm well aware of On Error Resume Next and On Error GoTo... this isn't gonna be that easy... :(
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
wellousCommented:
Oh yeah,
This is good that you discovered the issue already..
If your early binding by adding the reference then you will incur issues with different class interfaces between different versions.

You can late bind Excel by declaring the variable as an object and using createobject. You must however be aware that some functions may not be available in older versions of Excel..

<Code>
 Dim objEX As Object
 Set objEX = CreateObject("Excel.Application")
</Code>
You will also not have the intellisense associated with the early binding method

This link may help you with your Early/Late knowledge.
http://www.dicks-clicks.com/excel/ol...#Early_Binding


GL,
Wellous
0
 
wellousCommented:
 Dim objEX As Object
 Set objEX = CreateObject("Excel.Application")

Open in new window

0
 
Jeff9687Author Commented:
The late binding worked.
0
 
wellousCommented:
Glad to help,
Thanks for the grades
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now