Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

VBA-script not working in InDesign

Explorer ,
Jan 22, 2013 Jan 22, 2013

Goal: To have text placed from Word formatted in the paragraph styles I like. I receive the text from other authors and they are formatted with standard Word paragraph style formatting.

Two solutions:

  1. Format the text in Word (change paragraph styles) using VBA, place/import it and somehow make sure that InDesign uses the styles I already defined in InDesign, not the way that style is defined in Word. I can't figure out how to do this.
  2. Do the formatting in InDesign, using script. But the VBA-macro does not work in InDesign.

How may I change the code in order to work in InDesign? The code should look for specific paragraph styles and change them or the style of the next paragraph.

Sub stilSkifte()

Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext, Name:="1"

Dim para As Paragraph

For Each para In ActiveDocument.Paragraphs 'søk gjennom hvert enkelt avsnitt i dokumentet

  

   On Error Resume Next

  

    'INGEN MELLOMROM og overskriftene

    If para.Range.Style = "Ingen mellomrom" Then

        para.Style = "Normal"

        GoTo SisteLinje 'GÃ¥ til linja i koden som heter SisteLinje, = gÃ¥ til neste avsnitt

    End If

   

    If para.Range.Style = "Overskrift 1" Then

        para.Style = "Tittel-smÃ¥"

        GoTo SisteLinje 'GÃ¥ til linja i koden som heter SisteLinje, = gÃ¥ til neste avsnitt

    End If

   

    If para.Range.Style = "Overskrift 2" Then

        para.Style = "Ingress"

        GoTo SisteLinje 'GÃ¥ til linja i koden som heter SisteLinje, = gÃ¥ til neste avsnitt

    End If

   

    If para.Range.Style = "Overskrift 3" Then

        para.Style = "mellomtittel"

        GoTo SisteLinje 'GÃ¥ til linja i koden som heter SisteLinje, = gÃ¥ til neste avsnitt

    End If

   

  

    'NORMAL til BYLINE

    If para.Range.Style = "Ingress" Then

        If para.Next.Style = "Normal" Then

            para.Next.Style = "byline1"

        End If

           GoTo SisteLinje

    End If

   

    If para.Range.Style = "byline1" Then

        If para.Next.Style = "Normal" Then

            para.Next.Style = "byline2"

        End If

           GoTo SisteLinje

    End If

   'Hvis avsnittet er i NORMAL og det neste er...

    If para.Range.Style = "Normal" Then

       

        '...i NORMAL endres dette til NORMAL M INNRYKK

        If para.Next.Style = "Normal" Then

            para.Next.Style = "Normal med innrykk"

        End If

        GoTo SisteLinje

    End If

   

SisteLinje: Next

End Sub

I apriciate any suggestions!

TOPICS
Scripting
1.6K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Jan 22, 2013 Jan 22, 2013

VBA only works on Windows, of course, not on a Mac. You are working in

Windows, right?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 22, 2013 Jan 22, 2013

Yes, sorry!

I'm using:

  • Windows 7 Prof, 64-bit
  • Word 2007
  • InDesign CS5, version 7.0.4
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Jan 25, 2013 Jan 25, 2013

... place/import it and somehow make sure that InDesign uses the styles I already defined in InDesign, not the way that style is defined in Word. I can't figure out how to do this.

When you're placing a word document, turn on the "Show Import Options" check box, or hold "Shift" and click "Open". Then in the "Microsoft word options" dialog box choose "Use InDesign style definition" for paragraph and character styles conflicts.

1.png

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 25, 2013 Jan 25, 2013
LATEST

Thank you Kasyan, but it doesn't work as I expected it to. The InDesign style are somtimes overridden, sometimes not. It seems to have something to do with wether the Word-style is based on another Word-style or not. In addition I have my InDesign styles grouped, and when InDesign upon placing a text doesn't find the style on the top level, it imports the Word-style.

My solution:

  • Change Word-styles so they are not based upon another style
  • Running the VBA-code in Word
  • Placing the text using "Use InDesign style definition" for paragraph and character styles conflicts.
  • Editing the imported InDesign styles so that they are based upon and equals the original InDesign style in the respective group
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines