How to apply macro from file1 to file2? - excel

I have .csv files with different filenames put on a shared drive twice a day.
I need to apply a macro I wrote, (with much help) to the most recently created file with no user input so I can add it to Windows Task Scheduler.
For the task scheduler part I was going to use a PowerShell script.
How do I have Excel open a macro from file1 and run it on file2, where the filename on file2 changes daily?

I would recommend to store your macro in Personal Macro Workbook. With that you can run it on every excel file you open.
Here is how you do it:
https://support.office.com/en-us/article/create-and-save-all-your-macros-in-a-single-workbook-66c97ab3-11c2-44db-b021-ae005a9bc790

Related

Batch Script to Multiple Excel Files (1 variable)

I want to create a batch script that will take a .csv file that is tagged with a time stamp in the name open it, then open a specific macro-enabled Excel file (which will always be the same) and then run the macro in the 2nd workbook effective for the first workbook only.
So example:
BATCH:
for %%f in (PATH\*.csv) do ("C:\Program Files (x86)\Microsoft Office\root\Office16\EXCEL.EXE" "%%f")
I have this line to account for the changing time stamp
then the batch continues:
call PATH\Macro.xlsm
The CMD seems to stall after the first part and will not call the second file.
If I can have this open both files, can the macro run for all open workbooks rather than just the one it's built in via batch?
Any help would be appreciated as I am very new to this.

Running Multiple Excels having separate Macros without opening File

I have around 10 different excel files. For each file, I have a process saved in notepad
Every day i need to open each file, copy - paste the code from notepad to VB-excel & run the code
Is there any way I can kind of do this in batch file
Something like
Open File1
Run code of File1.
Save File 1
Repeat the same for File 2
Pls help
You should store your macro in a "Personal Workbook" described here.
The macros you store there load together with the Excel application and will be available to all workbooks you open.
In addition to the "Personal Workbook", I may even suggest automating that personal sub to open the workbooks automatically?
This could also potentially just point to a folder and For Each Workbook in definedSelectedWindowsPath
call subToAutomate()
similar to this
BIG thanks to Mr. Newman, he has certainly saved my back from a few sleepless coding problems.

How to write the excel file by Perl with VBA macro inside

My Perl scripts will write the excel file as the output to the user, and I also need this excel file includes the VBA codes.
That means after the use open the excel file, they can run the VBA macro by click the button.
Can I use Perl to write the excel file with macro inside?
If it is unable to do so, the workaround may be :
1. the Perl only write the excel file without macro.
2. attach the macro to that excel file before send to user

Excel 2010 VBA - Continually Looking In Folder for File to Process?

I have a need to build a macro in Excel 2010 that basically runs continually (started by button or stopped by button) that looks into a file folder. If a file is created there and named a certain way then the macro opens it and processes the data inside. The file is then closed and deleted. The macro then continues on to watch the file folder for more files to process
Is this a reasonable / doable macro that I could create in Excel with VBA? Can VBA continually run without issues?
Best Regards
Andy
Is your program continuously pulling changing data from the Excel sheet? If not, I would advise creating the program in another language and running in a continuous loop containing your code and the sleep() function. If so, then I would recommend using the worksheet change event, and you cannot edit the worksheet while a macro is running(even if you use the sleep/wait command in VBA)
This link might also prove helpful: How to get VBA Macro to run continuously in the background?
see this thread for some ideas:
https://superuser.com/questions/226828/how-to-monitor-a-folder-and-trigger-a-command-line-action-when-a-file-is-created
the first answer probably will do it, just trigger the excel macro you want from that. You can get as fancy as you want with the execution. The application.ontime function only works if excel is open, I believe.
What you want is to find a way to monitor the folder constantly.

Execute a dos command from an excel cell

I want to be able to run this command:
rename "845528004679 (1).jpg" "000001-000 (1).jpg"
from an excel cell, the same as if I were to open up ms dos and paste it in there.
Basically i have a macro to pull me down file list, it takes the UPC digits and vlooks up a product SKU and then adds the numbering and extension, then it makes the rename command and i want that to be executed without making another file or copy or pasting to another file
I haven't decided if I will add the file paths yet, just trying to find something similar I can work off of.
Thanks for anyone's help.
In VBA you can use FileCopy then Kill to delete the original version (there are other ways):
FileCopy "source", "destination"
Kill "source"
If you specifically want to run a batch command then you might investigate Shell but if it is this simple then I would use the above code.

Resources