![]() |
|
![]() |
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
![]()
I have a problem with .InsertCaption. I have been trying to look for solution on this site but I am not able to find a solution to my problem. I wonder if you could help me (again...
![]() The thing is that my code works sometimes and sometimes not. I have a tool that generate RTF documents and the generated documents need a lot of enhancement. I have therefore (with help from macropod earlier) created a VBA scripts that goes thru the whole document and fix TOC and TOF , fonts, labels etc. It also try to fix the caption for each figure that is in the document for TOF. The generated document contains tags that I am looking for ("CaptionFigureStart(*)CaptionFigureEnd") to replace them other tags in order later create the final result, see below. It always fails on the instruction “ .InsertCaption Label:="Figure", Title:=StrTxt, ExcludeLabel:=False” and the error message is sometimes “Command Failed” or “Runtime Error 4198 Command Failed”. The thing is that this code work perfect when I am running the WORD 2010 from an terminal server where I am logged into. But if I am using a Citrix Portal the scripts will be run by another Word installation which is also Word 2010 with English as the default language and also the very same settings regarding the “Trust Center Settings…”. On the Citrix Portal the code below will fail. I know it might be very hard to give me an answer why but my question is if the code below is very bad/poor and should be rewritten in order to run no matter where is called from. I have tried to create this script by looking at other similar scripts for finding, replacing and fixing the caption… Please see the attached file where you can see the progress of the script. Code:
Sub ConvertToCaption() ' ' Convert CaptionFigureStart and -End cotag to Cpation ' Dim RngTmp As Range, StrTmp As String, StrTxt As String, StrSreenTip As String With ActiveDocument.Range 'Convert CaptionFigureStart and -End codes to {CAPTIONLINK}\1 formatWith .Find .Text = "CaptionFigureStart(*)CaptionFigureEnd" .ClearFormatting .Replacement.ClearFormatting .Replacement.Text = "CAPTIONtempLINK: \1" .Forward = True .MatchWildcards = True .Wrap = wdFindStop .Execute Replace:=wdReplaceAll End With With .Find .Text = "CAPTIONtempLINK" .Replacement.Text = "" .Wrap = wdFindStop .Execute End With 'Convert Caption fields Do While .Find.Found = True Set RngTmp = .Duplicate .Text = Replace(.Text, "CAPTIONtempLINK", vbNullString, 1, -1, vbTextCompare) StrTxt = "" .InsertCaption Label:="Figure", Title:=StrTxt, ExcludeLabel:=False .Find.Execute Loop End With Set RngTmp = Nothing End Sub Last edited by macropod; 09-30-2014 at 08:11 PM. Reason: Added code tags & formatting |
#2
|
||||
|
||||
![]()
There is nothing about the code, per se, that would cause it to work when running WORD 2010 from a terminal server but not from a Citrix Portal. The problem is more likely to be something to do with the way the Citrix Portal is configured.
PS: When posting code, please use the code tags. They're on the 'Go Advanced' tab at the bottom of this screen.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
![]()
Hi Paul.
Thanks for your reply. Now I now at least that it is not because of the code. I will run more investigations around the configuration of the Citrix portal. Kind Regards, Benble. |
#4
|
|||
|
|||
![]() Quote:
CaptionLabels.Add Name:="Figure" ' always make sure we have we this label created before we use it Now it works from both the Terminal Server I am logged in to and also thru the Citrix portal. ![]() Kind Regards /Benble |
![]() |
Tags |
insertcaption |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
Ineedhelp! | Word | 3 | 03-04-2014 03:50 PM |
wildcards in find & replace to reverse word order | jeffk | Word | 3 | 11-11-2012 01:47 PM |
MS Word Find and Replace not working | allenglishboy | Word | 10 | 07-25-2012 08:05 AM |
![]() |
bthart | Word | 1 | 12-29-2011 12:45 AM |
![]() |
paulkaye | Word | 4 | 12-06-2011 11:05 PM |