Está en la página 1de 2

Este código abrirá el archivo Test.

xls y ejecutará la macro TestMacro que a su vez escribirá en el


archivo de texto TestResult.txt

Option Explicit

Dim xlApp, xlBook

Set xlApp = CreateObject("Excel.Application")


'~~> Change Path here
Set xlBook = xlApp.Workbooks.Open("C:\Test.xls", 0, True)
xlApp.Run "TestMacro"
xlBook.Close
xlApp.Quit

Set xlBook = Nothing


Set xlApp = Nothing

WScript.Echo "Finished."
WScript.Quit

Prueba

Sub TestMacro()
'first set a string which contains the path to the file you want to
create.
'this example creates one and stores it in the root directory
MyFile = "C:\Users\username\Desktop\" & "TestResult.txt"
'set and open file for output
fnum = FreeFile()
Open MyFile For Output As fnum
'write project info and then a blank line. Note the comma is required
Write #fnum, "I wrote this"
Write #fnum,
'use Print when you want the string without quotation marks
Print #fnum, "I printed this"
Close #fnum
End Sub

Re: Copiar datos desde un libro a otro sin necesidad de ...

Para leer del libro viejo Excel tendrá que abrirlo, otra cosa es que se le muestre el proceso
al usuario.
Prueba a crear un objeto workbook que se refiera al libro antiguo y con él das los pasos
necesarios para traer la información al libro nuevo

Dim LibroAntiguo As Workbook

Set LibroAntiguo = Workbooks.Open(RutaAlArchivo) 'la ruta que obtienes con


getopenfilename

With LibroAntiguo

'importas los datos que necesites

End With

LibroAntiguo.Close False 'cerramos sin guardar cambios

Set LibroAntiguo = Nothing

End Sub

si no quieres que el usuario vea el proceso puedes desactivar la actualización de la pantalla


durante la macro
Application.ScreenUpdating=false 'al principio del proceso

También podría gustarte