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)