Link to home
Create AccountLog in
Avatar of DavidAreen
DavidAreen

asked on

Macro for applying and removing shadows from Inlineshapes - Word 2003

I have the following code that will apply a shadow to all the inlineshapes within a document that works perfectly for Word 2007 and 2010.

However, for Word 2003, when the macro is run it does not like the

'Set shad = oInshp.Shadow'

and reports a "Method or Data statement" not found.

Can anyone advise on the code required to apply and then remove a shadow on an inlineshape for Word 2003?


*****************************************************

Sub AddShadow()

Dim oInshp As InlineShape
'+
'   Reset TotalInlineShapes
'-
TotalInlineShapes = 0
'+
'   Turn off the error handling as some problems can be ignored.
'-
On Error Resume Next
For Each oInshp In ActiveDocument.InlineShapes
 Set shad = oInshp.Shadow
 With shad
   .Type = msoShadow21
   .Blur = 12
   .OffsetX = 2
   .OffsetY = 3
 End With
'+
'   Increment the TotalInlineShapes
'-
 TotalInlineShapes = TotalInlineShapes + 1
Next oInshp
'+
'   Display the total number of charts where shadow has been applied
'-
MsgBox prompt:="Shadow applied to " & TotalInlineShapes & " Inline Shapes.", Title:="Menu Title", buttons:=vbInformation
'+
'   Reset the error handling.
'-
On Error GoTo 0
End Sub
****************************************
Avatar of GrahamSkan
GrahamSkan
Flag of United Kingdom of Great Britain and Northern Ireland image

This code, whose only modifications are to declare all variables and to allow errors to be reported works OK for me.
Sub AddShadow()

Dim oInshp As InlineShape
Dim TotalInlineShapes As Integer
Dim shad As ShadowFormat
'+
'   Reset TotalInlineShapes
'-
TotalInlineShapes = 0
'+
'   Turn off the error handling as some problems can be ignored.
'-
'On Error Resume Next
For Each oInshp In ActiveDocument.InlineShapes
 Set shad = oInshp.Shadow
 With shad
   .Type = msoShadow21
   .Blur = 12
   .OffsetX = 2
   .OffsetY = 3
 End With
'+
'   Increment the TotalInlineShapes
'-
 TotalInlineShapes = TotalInlineShapes + 1
Next oInshp
'+
'   Display the total number of charts where shadow has been applied
'-
MsgBox prompt:="Shadow applied to " & TotalInlineShapes & " Inline Shapes.", title:="Menu Title", Buttons:=vbInformation
'+
'   Reset the error handling.
'-
On Error GoTo 0
End Sub

Open in new window

Does it happen for all Inline shapes? If not, what sort of Inline shape does it fail on?
Avatar of DavidAreen
DavidAreen

ASKER

Thanks for the reply Graham

I have just cut and paste your whole code and tried it and get the same error.

Compile Error 'Method or data member not found', if yours is working under Word 2003 could it be that I need to check what references have been included?

Martin


>>Does it happen for all Inline shapes? If not, what sort of Inline shape does it fail on?

Just to fully explain, I have taken the code that was developed and working under Word 2010 and included it into a copy of Word 2003, the error is a compile error so comes up as soon as the subroutine is run.
Ah. My mistake. I tested it in Word 2007.

Actually, I don't remember using that in Word 2003. I'll run up my 2003 system and try it'
ASKER CERTIFIED SOLUTION
Avatar of GrahamSkan
GrahamSkan
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Thanks or confirming that.

I have managed use the following  code to convert an inlineshape to a shape and apply a shadow to the shape and then convert back. I'm not sure how to reverse the process and remove the shadow.


*****************
Sub AddShadow()

Dim oShp As Shape

Dim oInshp As InlineShape
Dim TotalInlineShapes As Integer
Dim shad As ShadowFormat
'+
'   Reset TotalInlineShapes
'-
TotalInlineShapes = 0

For Each oInshp In ActiveDocument.InlineShapes

 Set oShp = oInshp.ConvertToShape
 oShp.Shadow.Type = msoShadow12
 oShp.ConvertToInlineShape
'+
'   Increment the TotalInlineShapes
'-
 TotalInlineShapes = TotalInlineShapes + 1
Next oInshp
'+
'   Display the total number of charts where shadow has been applied
'-
MsgBox prompt:="Shadow applied to " & TotalInlineShapes & " Inline Shapes.", Title:="Menu Title", Buttons:=vbInformation
'+
'   Reset the error handling.
'-
On Error GoTo 0
End Sub
SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Sorry, I intended to reward Graham Skan with assisted solution but seem to have award the assist to me as well.
Sorry I intended to award Graham Skan's last reply with the assist, but seem to have awarded that to myself as well as the accepted solution.
Only average scored because the solution was confirmation that shadow object property doesn't work properly in Word 2003.