PDA

View Full Version : Why won't this simple code work anymore?



slang
01-03-2012, 08:32 AM
This code works in another section of the app but I can not get it to work anywhere else?:dunno
I can even record the macro and then try to play it back it comes back with "Compile Error, Variable not defined" on the "msoFalse" and "msoScaleFromTopLeft" parameters?

Sub Macro2()
'
' Macro2 Macro
' Macro recorded 1/3/2012
'
'
ActiveSheet.Shapes("dgapic1").Select
Selection.ShapeRange.ScaleWidth 1.4, , msoFalse, msoScaleFromTopLeft
Selection.ShapeRange.ScaleHeight 1.4, msoFalse, msoScaleFromTopLeft
Range("F30").Select
End Sub

This is in a module and ran in a sheet that has the correct picture object in place. Wierd this is there is code almost the same in other parts of the app and they work fine?:banghead:
Excel 2003

Is this another "Brain Fart" on my behalf?:rofl:
Man, I need to stay in VBA and not just jump back in when something needs fixed or changed.
Sorry if it is a simple one....

Paul_Hossler
01-03-2012, 09:06 AM
At least in my 2007, .ScaleWidth only takes 3 parameters



expression.ScaleWidth(Factor, RelativeToOriginalSize, Scale)



On the .ScaleWidth line


Selection.ShapeRange.ScaleWidth 1.4, , msoFalse, msoScaleFromTopLeft


you have 4, with the second one (, ,) being empty.

It looks like someone leaned too hard on the comma key :devil2:

Paul

slang
01-03-2012, 09:11 AM
Duh, Found it also.
Thanks Paul.
Need a coffee
Man, its like Monday!!!!
Sorry....:mkay

slang
01-03-2012, 09:44 AM
I thought I had it but I guess not.
Still gets the error on the "msoFalse" line.
Would it be the Activesheet.Pictures.insert(DGP1).select line?
It works everywhere else fine?:banghead: :banghead: :banghead:

ActiveSheet.Pictures.Insert(DGP1).Select
Selection.ShapeRange.IncrementLeft 178.5
Selection.ShapeRange.IncrementTop -84#
Selection.ShapeRange.ScaleWidth 0.25, msoFalse, msoScaleFromTopLeft
Selection.ShapeRange.ScaleHeight 0.25, msoFalse, msoScaleFromTopLeft

la la la la monday :aw

Paul_Hossler
01-03-2012, 11:00 AM
Maybe ....



ActiveSheet.Pictures.Insert( DGP1)
ActiveSheet.Pictures (DGP1).Select



not tested, but try two steps: Insert and then Select

Paul

Bob Phillips
01-03-2012, 11:02 AM
Can't reproduce the problem. Take a look in the VBIDE, Tools>References, and see if any items are marked [MISSING]. Uncheck them if so.