Skip to main content
Inspiring
November 28, 2022
Question

InDesign2014 goes into non-responding state when converting text variables to text

  • November 28, 2022
  • 2 replies
  • 779 views

Hi.

 

I have a VBA macro using variable.ConvertToText function to convert text variables to text.
This macro works well with different InDesign versions,
but now, when I run the macro for a document created in InDesign2014,
InDesign2014 goes into non-responding state.

 

In this document, there are tables, figures and the texts with two columns.
I have found that when InDesign2014 goes into non-responding state,
it's when the macro is converting a variable in a table.
This table has 1 row and 4 columns, and it is placed with a diagram in a text frame.
(The text frame contains a figure, and below the figure, the table with 1 row and 4 columns is placed.)
The text variable is set in a cell with no other text.

 

I have tried the following, but the problem is not solved.
1. Copy the document contents to a new document.
2. Export the document to idml, and reopen it in InDesign2014,then save as a Indesign document.

 

If I select the target variables from the TextVariables palette, and use the Convert To Text menu,
InDesign doesn't goes into non-responding state.

 

Because the InDesign version is specified, so I cannot use other versions of InDesign.

 

Please give me some advice.

This topic has been closed for replies.

2 replies

Community Expert
November 28, 2022

@erieru103 -- Can you show us your script?

erieru103Author
Inspiring
November 29, 2022

My code is the following.
Convert text variables to text only the character style or font applied them are the specified style.

Public Function ConvertToText(TgtIdDocs() As Object, idApp As Object)

  Dim var As Object
  Dim varName As String
  Dim i As Long, j As Long, k As Long
  
  
  For i = LBound(TgtIdDocs) To UBound(TgtIdDocs)
  
    Application.StatusBar = "Convert text variable to text in document " & i + 1 & "/" & UBound(TgtIdDocs) - LBound(TgtIdDocs) + 1 & " documents."
    
    If TgtIdDocs(i).TextVariables.Count > 0 Then
    
      For j = TgtIdDocs(i).TextVariables.Count To 1 Step -1
      
        Set var = TgtIdDocs(i).TextVariables.Item(j)
        varName = var.Name
        
        If IsTgtCharStyleVar(varName) = True Or IsTgtFontVar(varName) = True Then
        
          var.ConvertToText
          var.Delete
        
        End If
        
      Next
    
    End If
    
  Next
  
  Set var = Nothing
  
End Function
brian_p_dts
Community Expert
November 30, 2022

Not much of a VBA expert, but I suspect that if you are deleting the var after converting, you are throwing off your for loop. This commonly happens in JSX too when removing items from an array. Typically, to work around this, we iterate backward from the total length of the array down to 0. Edit: Nevermind, it looks like  you're doing that. But I suspect the hang has something to do with it; what if you remove the Delete call. Does it still hang? 

 

Community Expert
November 28, 2022

Hi @erieru103 ,

you could select the text using a script command and also use the menu command for converting text variables to text programmatically.

However, I cannot help with VBA. With ExtendScript this is possible for sure.

 

Regards,
Uwe Laubender
( Adobe Community Expert )

 

PS: Edited for clarification

Community Expert
November 28, 2022

With ExtendScript this is possible for sure.

But you don't know if it hangs InDesign 🙂