Inserting txt file into MS excel file from script?
Is there anyway i can execue any script by just one click that will insert a txt file into an already existant MS excel file?
i need to do this routine every day, i need to insert the content of certain txt file into a quite simple ms excel template, in the second row of the first column.
I thought there might be some way of automatizing this absurd task.
The txt source
The xlsx destination (need to be insterted from secon row first column
And a capture with the data separators that need to be removed whe importing from the txt
Id like to know how can this be achieve rather than just the script (which is good of course :) ) but i want to learn myself as i dont find a lot of documentation on this issue over the internet.
In excel you can use an Auto_Open macro or Workbook_Open Sub: http://office.microsoft.com/en-us/excel-help/running-a-macro-when-excel-starts-HA001034628.aspx
place code from my sample to sub. You can add to the end:
ActiveWorkbook.SaveAs Filename:="\\unc_file_name_with_path.xls", FileFormat _
:=xlNormal, Password:="", WriteResPassword:="", ReadOnlyRecommended:= _
True, CreateBackup:=FalseActiveWindow.Close
Application.Quit
if you like to close excel after import.
You can run this template from scheduler
Yes. You should have excel on computer, where it will be started. Look at sample. Place file to c:\tmp folder and run it from batch. You can open file with Shift pressed and auto_open macro execution will be stopped. Look at code in Module1 Book1.xlsm
How do i edit this so i can change header names? when i open the file for the second time it closes itself all the time. i tried to do it when opening for the first time the file so i would return a debug error but when saving it it would save without the macros it said.
also, the output name changes everyday, its not static, its filename_DD_MM_YY.xlsm
Ok, it seems to be improving, but i had to edit the code just right after executing and getting an error so i can debug, i can get this by deleting the source file too, but if the file is fine and the script works, there's no way of stoping the executing not even pressing shift+double click.
I need to change the source template, just a few things.
Don't release Shift until file will be opened.
Other way - temporarily increase safety level in Excel to "macros are disabled", edit code and set it back.
Oh ok, i could edit it by replacing the source file and provoking a debug, but it wouldn't stop executing by pressing Shift.
Anyway i made finally the script working. thank you very much, i can use it and i'll try to understand some parts of the code :)
well done!
Microsoft Excel
Microsoft Excel topics include formulas, formatting, VBA macros and user-defined functions, and everything else related to the spreadsheet user interface, including error messages.
Thanks,