Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 11-25-2014, 08:08 AM
Izzie7 Izzie7 is offline Return value of StyleRef n in VBA variable Windows 7 64bit Return value of StyleRef n in VBA variable Office 2010 32bit
Novice
Return value of StyleRef n in VBA variable
 
Join Date: Nov 2014
Location: Israel
Posts: 5
Izzie7 is on a distinguished road
Default Return value of StyleRef n in VBA variable

I want to change the Alternative Text and Title in InLine Shapes (there are a lot) to be the previous Heading 4 and Heading 3 respectively. I can set the value to a constant with this code, but I have not figured out how to set them to be = StyleRef N field values. Any ideas?

Sub Macro1()
'
' Macro1 Macro
' Alt_text_removal
'
m = ActiveDocument.InlineShapes.Count
For n = 1 To m
With ActiveDocument.InlineShapes.Item(n)
.AlternativeText = ""
.Title = ""


End With
Next n
End Sub
Reply With Quote
  #2  
Old 11-25-2014, 11:23 PM
macropod's Avatar
macropod macropod is offline Return value of StyleRef n in VBA variable Windows 7 64bit Return value of StyleRef n in VBA variable Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Getting the StyleRef result for a given page is far more complicated than looking for, say, the previous Heading, which you can do via a simple Find operation.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 11-26-2014, 03:43 AM
Izzie7 Izzie7 is offline Return value of StyleRef n in VBA variable Windows 7 64bit Return value of StyleRef n in VBA variable Office 2010 32bit
Novice
Return value of StyleRef n in VBA variable
 
Join Date: Nov 2014
Location: Israel
Posts: 5
Izzie7 is on a distinguished road
Default

I guess I am a novice since I usually just modify captures. I would have thought this would set H4 to hold the unformatted text of the previous Heading 4, but it just gives a null set when I step through it after selecting an inline shape.
Can you help?

Dim H4 As String
With Selection.Find
.Style = wdStyleHeading4
.Forward = False
.ClearFormatting
.Wrap = wdFindStop
.Execute
H4 = Selection.Text
End With
Reply With Quote
  #4  
Old 11-26-2014, 05:11 PM
macropod's Avatar
macropod macropod is offline Return value of StyleRef n in VBA variable Windows 7 64bit Return value of StyleRef n in VBA variable Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Try:
Code:
Sub Demo()
Dim i As Long, Rng As Range, StrAltTxt As String
With ActiveDocument
  'Loop through all inlineshapes
  For i = 1 To .InlineShapes.Count
    'Point our range to the start of the document
    Set Rng = .Range(0, 0)
    With .InlineShapes(i)
      'Point the end our range to the start of the inlineshape
      Rng.End = .Range.Start
      With Rng
        'Look backwards for a Heading 4
        With .Find
          .Text = ""
          .ClearFormatting
          .Replacement.Text = ""
          .Replacement.ClearFormatting
          .Format = True
          .Style = wdStyleHeading4
          .Forward = False
          .Wrap = wdFindStop
          .Execute
        End With
        If .Find.Found = True Then
          'If we found a Heading 4, get the text, minus the paragraph end
          With .Duplicate
            .End = .End - 1
            StrAltTxt = .Text
          End With
        End If
      End With
      'Add the Heading 4 text as the Alternative Text
      .AlternativeText = StrAltTxt
      .Title = ""
    End With
  Next
End With
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 11-27-2014, 04:30 AM
Izzie7 Izzie7 is offline Return value of StyleRef n in VBA variable Windows 7 64bit Return value of StyleRef n in VBA variable Office 2010 32bit
Novice
Return value of StyleRef n in VBA variable
 
Join Date: Nov 2014
Location: Israel
Posts: 5
Izzie7 is on a distinguished road
Default

Awesome! Thanks! It works fine except you forgot a period in the 8th line:
Should be:
With .InlineShapes(i)


Last edited by Izzie7; 11-27-2014 at 06:59 AM.
Reply With Quote
Reply

Tags
find & replace



Similar Threads
Thread Thread Starter Forum Replies Last Post
Run Time Error '91': Object variable or With block variable not set using Catalogue Mailmerge Berryblue Mail Merge 1 11-13-2014 05:36 PM
Return value of StyleRef n in VBA variable Run-time error 91 object variable or with block variable not set JUST ME Word VBA 4 03-25-2014 06:56 AM
Return value of StyleRef n in VBA variable object variable or with block variable not set MJP143 Excel 1 02-11-2013 05:07 AM
Return value of StyleRef n in VBA variable Run-time error '91': Object variable or With block variable not set tinfanide Excel Programming 2 06-10-2012 10:17 AM
Return value of StyleRef n in VBA variable Include URL in StyleRef? profliz Word 3 11-07-2011 09:20 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 11:16 PM.


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