Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 06-26-2024, 11:36 AM
JingleBelle JingleBelle is offline Error in Code for Checking Figure Numbers Windows 10 Error in Code for Checking Figure Numbers Office 2016
Novice
Error in Code for Checking Figure Numbers
 
Join Date: Nov 2020
Posts: 26
JingleBelle is on a distinguished road
Default Error in Code for Checking Figure Numbers

I routinely work with large documents that have many tables and figures. I have code that iterates through a document looking at all tables for captions. It looks for the presence of a field code above the table. If there isn't one, it adds a caption. I believe Andrew Lockton (a/k/a Guessed) graciously helped with this years ago. I have recently attempted to adapt the code for figures (inline shapes). Unfortunately, it adds a caption below all inline shapes whether or not a caption already exists. I am hoping an expert, here, can look at the code and identify the error(s) or tell me whether what I'm trying to accomplish can even be done.



Thank you in advance for considering my request for help.

Code:
Sub CheckAllFigures()
Dim iShape As InlineShape
Dim myBigRange As Range
Dim MyRange As Range
  
Application.ScreenUpdating = False
  
  On Error GoTo ErrorHandler
  Set myBigRange = ActiveDocument.Range
                'Process figures within the entire document
    For Each iShape In myBigRange.InlineShapes
        iShape.Select
                'Look at para below the figure. Caption there? If not, add one.
                    Selection.MoveDown Unit:=wdLine, Count:=1
                    Set MyRange = Selection.Paragraphs(1).Range
                    objShape.Select
                If MyRange.Fields.Count = 0 Then
                     Selection.InsertCaption Label:="Figure", TitleAutoText:="", _
                     Title:=". ", Position:=wdCaptionPositionBelow, ExcludeLabel:=0
                ElseIf MyRange.Fields(1).Type <> wdFieldSequence Then
                     Selection.InsertCaption Label:="Figure", TitleAutoText:="", _
                     Title:=". ", Position:=wdCaptionPositionBelow, ExcludeLabel:=0
                End If
     Next iShape  'Go to next shape
  Set MyRange = Nothing
  Set myBigRange = Nothing
  
Application.ScreenUpdating = True
Application.ScreenRefresh
MsgBox "Done!", vbInformation

Exit Sub 'If you get this far - avoid the error handler
ErrorHandler:
  MsgBox "Error: " & Err.Number & vbCr & Err.Description
End Sub
Reply With Quote
 

Tags
caption inline shapes, field code caption, inline shapes



Similar Threads
Thread Thread Starter Forum Replies Last Post
Error in Code for Checking Figure Numbers Figure number cross-referencing mess; figure numbers not updating. seanspotatobusiness Word 25 08-06-2018 05:00 PM
Table of Contents causes error when checking style NevilleT Word VBA 14 05-02-2018 01:23 AM
Trying to figure out this code sharpied Word 0 07-27-2016 12:09 PM
Error in Code for Checking Figure Numbers I want to add multiple rows into my document but I can not figure out the code jlw15931 Mail Merge 1 02-24-2015 05:03 AM
Can Word automatically update figure numbers? gib65 Word 7 02-22-2013 05:52 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 11:48 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft