Skip to main content
etiquetas editadas
Enlace
sstan
  • 16.9k
  • 2
  • 24
  • 48
se añadió 1 carácter en el cuerpo
Origen Enlace
Pikoh
  • 17.5k
  • 9
  • 41
  • 56
    Dim oApp As Word.Application
    Dim oDoc As Word.Document

    Dim arg()
    arg = Environment.GetCommandLineArgs()
    Dim destinoDoc As String = "carteles\"
    Dim nomFichero As String
    nomFichero = arg(1)
    Dim cDestino As String = "carteles\" + nomFichero + ".txt"

    My.Computer.FileSystem.CopyFile(My.Application.Info.DirectoryPath + "\Plantilla.dotx", My.Application.Info.DirectoryPath + "\" + nomFichero + ".dotx")

    Dim sPlantillaWord = "\" + nomFichero + ".dotx"

    oApp = CreateObject("Word.Application")
    oDoc = oApp.Documents.Add(My.Application.Info.DirectoryPath + "\" + nomFichero + ".dotx")

    With (oDoc.MailMerge)
        .MainDocumentType = Word.WdMailMergeMainDocType.wdNotAMergeDocument
        .OpenDataSource(Name:=My.Application.Info.DirectoryPath + "\" + cDestino)
        .Destination = Word.WdMailMergeDestination.wdSendToNewDocument
        .Execute()
    End With

    oDoc.Close(False)
    ...
    Dim oApp As Word.Application
    Dim oDoc As Word.Document

    Dim arg()
    arg = Environment.GetCommandLineArgs()
    Dim destinoDoc As String = "carteles\"
    Dim nomFichero As String
    nomFichero = arg(1)
    Dim cDestino As String = "carteles\" + nomFichero + ".txt"

    My.Computer.FileSystem.CopyFile(My.Application.Info.DirectoryPath + "\Plantilla.dotx", My.Application.Info.DirectoryPath + "\" + nomFichero + ".dotx")

    Dim sPlantillaWord = "\" + nomFichero + ".dotx"

    oApp = CreateObject("Word.Application")
    oDoc = oApp.Documents.Add(My.Application.Info.DirectoryPath + "\" + nomFichero + ".dotx")

    With (oDoc.MailMerge)
        .MainDocumentType = Word.WdMailMergeMainDocType.wdNotAMergeDocument
        .OpenDataSource(Name:=My.Application.Info.DirectoryPath + "\" + cDestino)
        .Destination = Word.WdMailMergeDestination.wdSendToNewDocument
        .Execute()
    End With

    oDoc.Close(False)
    ...

Excepción no controlada: System.Runtime.InteropServices.COMException: Word no pudo abrir el origen de datos. en Microsoft.Office.Interop.Word.MailMerge.OpenDataSource(String Name, Object& Format, Object& ConfirmConversions, Object& ReadOnly, Object& LinkToSource, Object& AddToRecentFiles, Object& PasswordDocument, Object& PasswordTemplate, Object& Revert, Object& WritePasswordDocument, Object& WritePasswordTemplate, Object& Connection, Object& SQLStatement, Object& SQLStatement1, Object& OpenExclusive, Object& SubType)

Excepción no controlada: System.Runtime.InteropServices.COMException: Word no pudo abrir el origen de datos. en Microsoft.Office.Interop.Word.MailMerge.OpenDataSource(String Name, Object& Format, Object& ConfirmConversions, Object& ReadOnly, Object& LinkToSource, Object& AddToRecentFiles, Object& PasswordDocument, Object& PasswordTemplate, Object& Revert, Object& WritePasswordDocument, Object& WritePasswordTemplate, Object& Connection, Object& SQLStatement, Object& SQLStatement1, Object& OpenExclusive, Object& SubType)

    Dim oApp As Word.Application
    Dim oDoc As Word.Document

    Dim arg()
    arg = Environment.GetCommandLineArgs()
    Dim destinoDoc As String = "carteles\"
    Dim nomFichero As String
    nomFichero = arg(1)
    Dim cDestino As String = "carteles\" + nomFichero + ".txt"

    My.Computer.FileSystem.CopyFile(My.Application.Info.DirectoryPath + "\Plantilla.dotx", My.Application.Info.DirectoryPath + "\" + nomFichero + ".dotx")

    Dim sPlantillaWord = "\" + nomFichero + ".dotx"

    oApp = CreateObject("Word.Application")
    oDoc = oApp.Documents.Add(My.Application.Info.DirectoryPath + "\" + nomFichero + ".dotx")

    With (oDoc.MailMerge)
        .MainDocumentType = Word.WdMailMergeMainDocType.wdNotAMergeDocument
        .OpenDataSource(Name:=My.Application.Info.DirectoryPath + "\" + cDestino)
        .Destination = Word.WdMailMergeDestination.wdSendToNewDocument
        .Execute()
    End With

    oDoc.Close(False)
    ...

Excepción no controlada: System.Runtime.InteropServices.COMException: Word no pudo abrir el origen de datos. en Microsoft.Office.Interop.Word.MailMerge.OpenDataSource(String Name, Object& Format, Object& ConfirmConversions, Object& ReadOnly, Object& LinkToSource, Object& AddToRecentFiles, Object& PasswordDocument, Object& PasswordTemplate, Object& Revert, Object& WritePasswordDocument, Object& WritePasswordTemplate, Object& Connection, Object& SQLStatement, Object& SQLStatement1, Object& OpenExclusive, Object& SubType)

    Dim oApp As Word.Application
    Dim oDoc As Word.Document

    Dim arg()
    arg = Environment.GetCommandLineArgs()
    Dim destinoDoc As String = "carteles\"
    Dim nomFichero As String
    nomFichero = arg(1)
    Dim cDestino As String = "carteles\" + nomFichero + ".txt"

    My.Computer.FileSystem.CopyFile(My.Application.Info.DirectoryPath + "\Plantilla.dotx", My.Application.Info.DirectoryPath + "\" + nomFichero + ".dotx")

    Dim sPlantillaWord = "\" + nomFichero + ".dotx"

    oApp = CreateObject("Word.Application")
    oDoc = oApp.Documents.Add(My.Application.Info.DirectoryPath + "\" + nomFichero + ".dotx")

    With (oDoc.MailMerge)
        .MainDocumentType = Word.WdMailMergeMainDocType.wdNotAMergeDocument
        .OpenDataSource(Name:=My.Application.Info.DirectoryPath + "\" + cDestino)
        .Destination = Word.WdMailMergeDestination.wdSendToNewDocument
        .Execute()
    End With

    oDoc.Close(False)
    ...

Excepción no controlada: System.Runtime.InteropServices.COMException: Word no pudo abrir el origen de datos. en Microsoft.Office.Interop.Word.MailMerge.OpenDataSource(String Name, Object& Format, Object& ConfirmConversions, Object& ReadOnly, Object& LinkToSource, Object& AddToRecentFiles, Object& PasswordDocument, Object& PasswordTemplate, Object& Revert, Object& WritePasswordDocument, Object& WritePasswordTemplate, Object& Connection, Object& SQLStatement, Object& SQLStatement1, Object& OpenExclusive, Object& SubType)

Origen Enlace
David
  • 53
  • 1
  • 2
  • 8

Error Mail Merge word

estoy desarrollando un programa en visual basic y lo que quiero hacer es lo siguiente: a partir de un fichero .txt rellenar una plantilla de word (.dotx). El fichero de texto tiene una cabecera separada por tabulaciones y debajo una seria de filas con los datos (también separados por tabulaciones).

el código que tengo es el siguiente

    Dim oApp As Word.Application
    Dim oDoc As Word.Document

    Dim arg()
    arg = Environment.GetCommandLineArgs()
    Dim destinoDoc As String = "carteles\"
    Dim nomFichero As String
    nomFichero = arg(1)
    Dim cDestino As String = "carteles\" + nomFichero + ".txt"

    My.Computer.FileSystem.CopyFile(My.Application.Info.DirectoryPath + "\Plantilla.dotx", My.Application.Info.DirectoryPath + "\" + nomFichero + ".dotx")

    Dim sPlantillaWord = "\" + nomFichero + ".dotx"

    oApp = CreateObject("Word.Application")
    oDoc = oApp.Documents.Add(My.Application.Info.DirectoryPath + "\" + nomFichero + ".dotx")

    With (oDoc.MailMerge)
        .MainDocumentType = Word.WdMailMergeMainDocType.wdNotAMergeDocument
        .OpenDataSource(Name:=My.Application.Info.DirectoryPath + "\" + cDestino)
        .Destination = Word.WdMailMergeDestination.wdSendToNewDocument
        .Execute()
    End With

    oDoc.Close(False)
    ...

Al ejecutarlo en local me funciona perfectamente, pero al ejecutarlo por ssh me da un error que no consigo solucionar.

Excepción no controlada: System.Runtime.InteropServices.COMException: Word no pudo abrir el origen de datos. en Microsoft.Office.Interop.Word.MailMerge.OpenDataSource(String Name, Object& Format, Object& ConfirmConversions, Object& ReadOnly, Object& LinkToSource, Object& AddToRecentFiles, Object& PasswordDocument, Object& PasswordTemplate, Object& Revert, Object& WritePasswordDocument, Object& WritePasswordTemplate, Object& Connection, Object& SQLStatement, Object& SQLStatement1, Object& OpenExclusive, Object& SubType)

alguna idea?