Jump to content
Fórum Script Brasil
  • 0

CÓDIGO COM ERRO DE SINTAXE


Question

O código não está rodando, tem um erro de sintaxe na parte que selecionei vermelha e diz também que o Sub não está presente. A ideia é pegar nomes em uma planilha e salvar arquivos de mala direta separadamente, com os nomes selecionados.

 

Sub BreakOnSection()
Dim Arquivo As Integer
Dim CaminhoArquivo As String
Dim TextoProximaLinha As String

'Set reading the file that contains the names of files that will be generated.
Arquivo = FreeFile
CaminhoArquivo = "C:\Users\Bepler\Desktop\aqui\655A7100.xlsm"

'Open file for reading.
Open CaminhoArquivo For Input As Arquivo

'Used to set criteria for moving through the document by section.
Application.Browser.Target = wdBrowseSection

'A mail merge document ends with a section break next page.
'Subtracting one from the section count stop error message.
For i = 1 To ((ActiveDocument.Sections.Count) - 1)
    'Note: If a document does not end with a section break,
    'substitute the following line of code for the one above:
    'For I = 1 To ActiveDocument.Sections.Count

    'Select and copy the section text to the clipboard.
    ActiveDocument.Bookmarks("\Section").Range.Copy

    'Create a new document to paste text from clipboard.
    Documents.Add
    Selection.Paste

    
    'Deletes the last page (use only if necessary)
    DeleteLastLine

    'Removes the break that is copied at the end of the section, if any.
    Selection.MoveUp Unit:=wdLine, Count:=1, Extend:=wdExtend
    Selection.Delete Unit:=wdCharacter, Count:=1
    ChangeFileOpenDirectory "\\BEPLER-PC\Users\Bepler\Desktop\aqui\Termos\Máscaras"

    'It makes the line reading
    Line Input #nomemb, TextoProximaLinha
    TextoProximaLinha = TextoProximaLinha

    'save to .docx and customize the file name to the line that was read
     ActiveDocument.saveAsFixedFormat OutputFileName:= _
    "\\BEPLER-PC\Users\Bepler\Desktop\aqui\Termos\Máscaras" & TextoProximaLinha & ".docx" _
    , saveFormat:=wdsaveFormat.docx, OpenAftersave:=False, OptimizeFor:=

    wdsaveOptimizeForPrint , Range:=wdsaveAllDocument, From:=1, To:=1, _
    Item:=wdsveDocumentContent, IncludeDocProps:=True, KeepIRM:=True, _
    CreateBookmarks:=wdsaveCreateNoBookmarks, DocStructureTags:=True, _
    BitmapMissingFonts:=True, UseISO19005_1:=False

    'Closes the "temporary" file from Word without saving changes
    ActiveDocument.Close savechanges:=wdDoNotSaveChanges
    'Move the selection to the next section in the document.
    Application.Browser.Next
Next i
        ActiveDocument.Close savechanges:=wdDoNotSaveChanges
End Sub

Sub Orientation()
    'If the page orientation is portrait in it is changed to landscape
    'This is a particular case in issuing certificates. Make sure that in your case there is a need
    If Selection.PageSetup.Orientation = wdOrientPortrait Then
        Selection.PageSetup.Orientation = wdOrientLandscape
    Else
    Selection.PageSetup.Orientation = wdOrientPortrait
    End If
ActiveWindow.ActivePane.VerticalPercentScrolled = 0
End Sub

Sub DeleteLastLine()
'This is a particular case in issuing certificates. Make sure that in your case there is a need
    Selection.HomeKey Unit:=wdStory
    Selection.EndKey Unit:=wdStory
    Selection.MoveLeft Unit:=wdCharacter, Count:=1
    Selection.Delete Unit:=wdCharacter, Count:=1
    Selection.Delete Unit:=wdCharacter, Count:=1
    Selection.Delete Unit:=wdCharacter, Count:=1
    Selection.Delete Unit:=wdCharacter, Count:=1
    Selection.Delete Unit:=wdCharacter, Count:=1
End Sub

 

😊 Muito obrigadinha pela atenção!

Link to post
Share on other sites

2 answers to this question

Recommended Posts

  • 0

Bom dia @Sabrina Beppler, Eu coloquei o código no meu excel e encontrei um falha na compo em vermelho:

Seu código:

...

    'save to .docx and customize the file name to the line that was read
     ActiveDocument.saveAsFixedFormat OutputFileName:= _
    "\\BEPLER-PC\Users\Bepler\Desktop\aqui\Termos\Máscaras" & TextoProximaLinha & ".docx" _
    , saveFormat:=wdsaveFormat.docx, OpenAftersave:=False, OptimizeFor:=
    wdsaveOptimizeForPrint , Range:=wdsaveAllDocument, From:=1, To:=1, _
    Item:=wdsveDocumentContent, IncludeDocProps:=True, KeepIRM:=True, _
    CreateBookmarks:=wdsaveCreateNoBookmarks, DocStructureTags:=True, _
    BitmapMissingFonts:=True, UseISO19005_1:=False
...

Correção:
 

...

   'save to .docx and customize the file name to the line that was read
     ActiveDocument.saveAsFixedFormat OutputFileName:= _
    "\\BEPLER-PC\Users\Bepler\Desktop\aqui\Termos\Máscaras" & TextoProximaLinha & ".docx" _
    , saveFormat:=wdsaveFormat.docx, OpenAftersave:=False, OptimizeFor:= _
    wdsaveOptimizeForPrint, Range:=wdsaveAllDocument, From:=1, To:=1, _
    Item:=wdsveDocumentContent, IncludeDocProps:=True, KeepIRM:=True, _
    CreateBookmarks:=wdsaveCreateNoBookmarks, DocStructureTags:=True, _
    BitmapMissingFonts:=True, UseISO19005_1:=False
...

Na quarta linha faltou o "_" underline para que a linha debaixo junte a de cima.

Olha se vai funcionar agora.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Cloud Computing


  • Forum Statistics

    • Total Topics
      148954
    • Total Posts
      645015
×
×
  • Create New...