Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Macro for applying and removing shadows from Inlineshapes - Word 2003

Posted on 2010-11-11
11
Medium Priority
?
1,714 Views
Last Modified: 2013-11-05
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
****************************************
0
Comment
Question by:DavidAreen
  • 7
  • 4
11 Comments
 
LVL 77

Expert Comment

by:GrahamSkan
ID: 34110798
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

0
 
LVL 77

Expert Comment

by:GrahamSkan
ID: 34110817
Does it happen for all Inline shapes? If not, what sort of Inline shape does it fail on?
0
 
LVL 1

Author Comment

by:DavidAreen
ID: 34110844
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


0
Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

 
LVL 1

Author Comment

by:DavidAreen
ID: 34110965
>>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.
0
 
LVL 77

Expert Comment

by:GrahamSkan
ID: 34111521
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'
0
 
LVL 77

Accepted Solution

by:
GrahamSkan earned 260 total points
ID: 34112021
The Shadow Object property doesn't work properly in Word 2003 VBA code.

It is possible to record a macro while setting the shadow:

Selection.ShapeRange.Shadow.Type = msoShadow17

or

Selection.InLineShapes(1).Shadow.Type = msoShadow17

but neither code works properly.

The Inline code raises the error that you got. No error is raised for Shape objects, but the picture is replaced with the shadow colour.

0
 
LVL 1

Author Comment

by:DavidAreen
ID: 34112367
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
0
 
LVL 1

Assisted Solution

by:DavidAreen
DavidAreen earned 0 total points
ID: 34114097
I stand corrected, converting the inlineshape to a shape and then applying the shadow doesn't seem to be a workable solution.

I have decided that it would be simpler to check the version of Word that is running and display a message to the effect that the shadow macro is unsupported for Word 2003.
0
 
LVL 1

Author Comment

by:DavidAreen
ID: 34114449
Sorry, I intended to reward Graham Skan with assisted solution but seem to have award the assist to me as well.
0
 
LVL 1

Author Comment

by:DavidAreen
ID: 34114470
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.
0
 
LVL 1

Author Closing Comment

by:DavidAreen
ID: 34143468
Only average scored because the solution was confirmation that shadow object property doesn't work properly in Word 2003.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you work with Word a lot, you probably use styles. If you use styles a lot, you've probably balled your fist more often than not when working with the ribbon. In Word 2007/2010, one of the things that I find missing when using styles is a quic…
Microsoft Word is a program we have all encountered at some point, but very few of us have dug deep into its full scope of features, let alone customized it to suit our needs. Luckily making the ribbon (aka toolbar, first introduced in Word 2007) wo…
Office 365 is currently available in five editions. Three of them are for business use: Office 365 Business Essentials, Office 365 Business, and Office 365 Business Premium. Two of them are for home/personal use: Office 365 Home and Office 365 Perso…
In a previous video Micro Tutorial here at Experts Exchange (http://www.experts-exchange.com/videos/1358/How-to-get-a-free-trial-of-Office-365-with-the-Office-2016-desktop-applications.html), I explained how to get a free, one-month trial of Office …
Suggested Courses

577 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question