Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #5  
Old 01-07-2015, 03:44 PM
jjfreedman jjfreedman is offline Referencing FieldCodes in VBA Windows 7 64bit Referencing FieldCodes in VBA Office 2013
Advanced Beginner
 
Join Date: May 2012
Location: https://jay-freedman.info
Posts: 39
jjfreedman is on a distinguished road
Default

When you collapse the Selection, that excludes the field that you just inserted, and in turn the field is excluded from objRange -- that's why it doesn't appear in the building block.

Replace this part of your code

Code:
    ' Collapse the range, set the range, and add the text
    Selection.Collapse
    Set objRange = Selection.Range
 
    objRange.Text = "Building blocks for the technically challenged"
with this:

Code:
    ' Collapse the range, set the range, and add the text
    Selection.Collapse
    Set objRange = Selection.Range
 
    objRange.Text = vbCr & "Building blocks for the technically challenged"
    objRange.MoveStart unit:=wdCharacter, Count:=-1
That works for me. If the "technically challenged" text appears for you before the chart instead of after it, you'd have to replace the MoveStart with MoveEnd and change the Count value from -1 to 1. (Just as when using the mouse or arrow keys, selecting just the opening or closing field marker automatically selects the entire field.)
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Using FieldCodes, AutoText, BuildingBlocks ptmuldoon Word 5 01-02-2015 01:33 PM
Auto referencing SharkAttack Word 5 02-17-2013 07:09 PM
Referencing darksupernova Word 4 11-08-2012 03:37 AM
Multiple referencing SPRITEtoo Word 3 01-29-2012 07:39 PM
Cross referencing maltesedog Word 0 02-13-2009 07:43 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:31 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