4 Replies Latest reply on Jan 25, 2013 2:31 AM by IngyNorw

    VBA-script not working in InDesign

    IngyNorw Level 1

      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!

        • 1. Re: VBA-script not working in InDesign
          TᴀW Adobe Community Professional & MVP

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

          Windows, right?

          • 2. Re: VBA-script not working in InDesign
            IngyNorw Level 1

            Yes, sorry!

             

            I'm using:

            • Windows 7 Prof, 64-bit
            • Word 2007
            • InDesign CS5, version 7.0.4
            • 3. Re: VBA-script not working in InDesign
              Kasyan Servetsky Level 5

              ... 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

              • 4. Re: VBA-script not working in InDesign
                IngyNorw Level 1

                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