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.
Related
For my work i need to track what cases i did. Right now i note all the case numbers in an excel file where i also sort them to the categorie they belong. At the end of every week i then have to put in the numbers in our tracking tool with copy and paste (tracking tool isnt on the same desktop i work on so i cant do it directly)
So i thought maybe it would be possible to write a macro in the excel file that does the copy paste for me but i already fail when i want to switch from the excel to the tracking tool
I tried shell activate and windows activate but i only get run time errors
Im grateful for any help even different approches
Please add screenshots and more explaination of the scenario so we could have better insights
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
I have just started vorking with vba, and am slowly getting the hang of it.
I have a question as to the posibility of something:
I have an Excel sheet where I have part of the names of a lot of text datasheets I need to copy.
My folder destination is the following:
Same folder/Name from column F/Name from column B/text files with the string x in the name...
Is it at all possible to copy files like this from one folder to another?
I am thinking a for loop and a bunch of if statements?
Best Regards
Lonnie
To build on Alex's answer, and to confirm what you suspected already, you need to loop through all the files in the originating directory using the Dir command (this tutorial is a bit more readable than the msdn one: https://www.techonthenet.com/excel/formulas/dir.php)
then decide whether to move the file based on a rule (see here for string manipulation: http://www.excel-easy.com/vba/string-manipulation.html)
Finally, if the conditions are fulfilled, use the .copyfile command that Alex suggests in the comments.
I have about 10000 excel files, that in a specific cell of all of them there is a picture. I need a script to read all files and save the picture with the same name of the excel files in a folder.
Could you please help with that?
Thanks.
This method is based on a number of assumptions:
All the files (10000) are located in a know folder,
All files are named according to a paradigm that can be reproduced programmatically (if not, you can get the list of files within the folder, store the list within an array, and loop through the array),
Pictures are always within the same worksheet or, if in more than one, the names of the worksheets can be reproduced programmatically,
The filenames to be used to save the pictures can match (at least as a seed) the one of the Excel the pictures are extracted,
You will manage to write some basic VBA.
Note that for the VBA you have at least two options:
Write it within an EXCEL that will only serve as the extraction engine, or
Write it as a stand-alone file and run it via DOS commands.
The VBA logic:
Create the outer loop that processes a single file,
Within the outer loop, generate the name of a file to be open,
Open the file using Workbooks.Open VBA function,
Select the worksheet and the cell containing the picture,
Use the Workbook.SaveAs to save the picture (you will need to specify the type of file to be used, e.g. .bmp).
As a simple and very efficient tool to get the code (at least) partially generated by Excel, you can RECORD a MACRO for each action and then stop recording. You will see the code generated (you will need to access the VBA mode). You can copy-paste the generated code into your development (you might need to do some simple adaptations though).
That's it.
Hope you manage. Good luck!!
In a perl script I am writing, I am trying to find a way to open an existing excel spreadsheet, change the name of the first worksheet, and save it. It would seem like a simple task but I haven't found a simple way to do it.
Spreadsheet::WriteExcel can easily change worksheet name, but it seems like it can't read in an existing excel file.
Another constraint is that the perl module I use shouldn't need installation. I can work around this if there's no good option, but it would make things more complicated.
Edit: I am using ActivePerl 5.18, so modules included in this are ideal.
The only way of doing this while preserving everything else in the Excel file is to use Win32::OLE.
That requires having Excel installed on the computer on which the program will be run, and, of course, only works on Windows.
If you can't do that, you will have to read the Excel file, and write out the contents to another file, changing the name of the worksheet in the process. Depending on exactly what you have in the source Excel file, this can get rather involved rather fast.
See also "How can I merge two Excel (xls) files in Perl or batch?" and "In Perl, how can I copy a subset of columns from an XLSX work sheet to another?"