Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-04-2022, 11:16 PM
avogt avogt is offline Edit Reference in Word bv VBA Windows 7 64bit Edit Reference in Word bv VBA Office 2016
Novice
Edit Reference in Word bv VBA
 
Join Date: Apr 2018
Posts: 4
avogt is on a distinguished road
Default Edit Reference in Word bv VBA


Hello,
I try to insert a Reference in Word via VBA by code:
Code:
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
Selection.EndKey Unit:=wdStory
Selection.InsertCrossReference ReferenceType:="Textmarke", ReferenceKind:=wdContentText, _
ReferenceItem:="T_LIEFERANTENERGAENZUNG_BERECHNUNG", InsertAsHyperlink:=True, _
IncludePosition:=False, SeparateNumbers:=False, SeparatorString:=" "
But I need to add the "\*MERGEFORMAT" formatting to this reference.
So I tried to loop trough all fields by code:
Code:
Dim fieldLoop As Field
    Dim fieldText As String
    For Each fieldLoop In ActiveDocument.Fields
       If InStr(0, fieldLoop.Code.Text, "REF T_LIEFERANTENERGAENZUNG_BERECHNUNG", 1) Then
          fieldText = fieldLoop.Code.Text
          If InStr(1, fieldText, " \h", 1) And Not InStr(1, fieldText, " \* MERGEFORMAT", 1) Then
             fieldText = fieldText & " \* MERGEFORMAT "
             fieldLoop.Code.Text = fieldText
           End If
        End If
    Next
But the Loop does not find the Reference I added before..

Any Ideas how to add the formating to this field?
It is located in the header on page 2..

thanks
Andreas
Reply With Quote
  #2  
Old 07-06-2022, 07:30 AM
macropod's Avatar
macropod macropod is offline Edit Reference in Word bv VBA Windows 10 Edit Reference in Word bv VBA Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
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 RefDemo()
Application.ScreenUpdating = False
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
With Selection
  .EndKey Unit:=wdStory
  .Fields.Add .Range, wdFieldEmpty, Text = "REF T_LIEFERANTENERGAENZUNG_BERECHNUNG \* MERGEFORMAT \h", False
End With
Application.ScreenUpdating = True
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Tags
formating, vba

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Edit Reference in Word bv VBA Determining if an in-text table reference was created with Word's native cross reference feature scienceguy Excel Programming 2 10-25-2021 04:44 AM
How to edit add-ons panel in word 2010 created in word 2000 alexxmore Word 2 03-18-2020 04:45 AM
How do I edit my TOC to reference the section numbers instead of the page numbers??? mikey386 Word 0 12-17-2014 02:34 PM
Edit Reference in Word bv VBA Reference number and cross reference for equation numbers to match the thesis format wmac Word 1 05-14-2013 08:54 PM
MarkAsFinal - 'Edit Anyway' edit popup issue GovindRS PowerPoint 1 06-20-2011 06:43 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 10:39 AM.


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