Problema de error de VBA Word Selection.PasteAndFormat (wdFormatOriginalFormatting) – Visual Basic

¡Bienvenidos!

Información básica: Windows 10, Office 19.

Estaba buscando una solución a un error con la función de letras circulares en Word, que coloca todas las cartas preparadas en un solo documento, por lo que puede imprimirlas, pero no puedo enviarlas a todos los involucrados por correo electrónico.

Encontré el siguiente código en la red, que personalicé:


Option Explicit
Dim FajlNev As String
Dim Korlevel As Document
Dim TempDoc As Document
Dim strPath As String

Sub Korlevelbol_Egyedi_Levelek()

Dim i As Long
Set Korlevel = ThisDocument

Application.Browser.Target = wdBrowseSection
'Application.Browser.Target = wdSectionBreakNextPage

For i = 1 To ((Korlevel.Sections.Count) - 1)
'For i = 1 To ((Korlevel.SectionBreakNextPage.Count) - 1)
Korlevel.Bookmarks("\Section").Range.Copy

Set TempDoc = Documents.Add

Selection.PasteAndFormat (wdFormatOriginalFormatting)
With TempDoc.PageSetup
.TopMargin = CentimetersToPoints(1.5)
.BottomMargin = CentimetersToPoints(1)
.LeftMargin = CentimetersToPoints(1.5)
.RightMargin = CentimetersToPoints(1.5)
.Gutter = CentimetersToPoints(0)
End With

'Selection.PasteAndFormat Type:=wdFormatOriginalFormatting

Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.Delete Unit:=wdCharacter, Count:=1

'strPath = Korlevel.Path & Application.PathSeparator

FajlNev = TempDoc.Tables(1).Rows(1).Cells(2).Range.Text
TempDoc.ExportAsFixedFormat OutputFileName:= _
strPath & FajlNev & ".pdf", ExportFormat:=wdExportFormatPDF, _
OpenAfterExport:=False, OptimizeFor:=wdExportOptimizeForPrint, Range:= _
wdExportAllDocument, From:=1, To:=1, Item:=wdExportDocumentContent, _
IncludeDocProps:=True, KeepIRM:=True, CreateBookmarks:= _
wdExportCreateNoBookmarks, DocStructureTags:=True, BitmapMissingFonts:= _
True, UseISO19005_1:=False

TempDoc.Close savechanges:=wdDoNotSaveChanges
'TempDoc.Close wdDoNotSaveChanges
Application.Browser.Next
Next i
MsgBox (i - 1 & " db Kész.")
End Sub

el programa es un archivo
Selection.PasteAndFormat (wdFormatOriginalFormatting)
Se detiene con un mensaje de error. el error es:

Error de tiempo de ejecución «4605»
Este comando no está disponible.

No entiendo dos cosas. En primer lugar, copié las instrucciones de la macro grabada hace minutos y, en segundo lugar, después de seleccionar la opción Depurar, después de abrir el editor de VBA, la macro se ejecuta en la instrucción F5, hace el trabajo y luego se detiene allí.

READ  Google Pixel 6 y Google Pixel 6 Pro son sorprendentemente baratos

Vi en la red que el problema aparecía en varios lugares, pero lamentablemente no encontré solución

¡Gracias de antemano por tu ayuda!
Saludos: Kero

Deja un comentario

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *

Scroll al inicio