I have written a macro which opens 2 comma delimited files (Generic Tables used by Prophet 8.1 ending with a .fac extension), does a comparison and creates another workbook which highlights all the differences.
The macro seems to fail when the files have the same name but has different directories.
What would be the easiest way to overcome this problem without having to actually change the file name as seen in the location? It is against company policy to mess with the actual files as seen in the location. Is there a way to assign some temporary name to the file and not save it?
In Excel you cannot have two files open with the same name!
If you don't want to rename the files, copy one temporarily using a different name - and delete it afterwards (assuming you only want to read from it)
If you have to modify/save the original files, then the only two options you have is to rename them (you can afterwards rename them back to the original name) - or change your procedure so only one file is open at the time (e.g. by temporarily storing some data from the first file in a temp workbook that gets created and closed during the code execution).
Related
I need some advice around copying Excel files and then keeping a 'template' once it's moved. I have a bunch of Excel files that need to be loaded into SQL. The names might differ, i.e. Excel_Test1, Excel_Test2. These files are processed into SQL. Once this is done I have to copy them into an Archive folder. The problem is if I move instead of copy I get the error in my SSIS package where it says object doesn't exist. What can I do to ensure it doesn't happen? Is there a way to copy the files to archive, and then create a dynamic Excel sheet for next time? Or is there an easier way of doing this? Steps are:
Truncate Staging Table.
Load first table.
Load second table.
Move / copy files to archive.
I hope I'm making sense.
Keep one version of file in Template folder
(it can contain fake data if it make sense), then copy actual file to archive after processing, and then override the actual file with file from Template folder.
I have multiple Excel files in the same format and I want to combine them into a single file.
How can I merge them into one single excel file using VBA?
VBA is no longer required to merge files. You can use Power Query and merge all files in the same folder with just a few clicks. When the files change, you just update the query.
You have two choices:
a "flat" file, in which all the data are in a single sheet (BAD)
A multi-sheet file (GOOD)
In the first case open a new file, cut and paste your existing content into the new (single) sheet
In the second case Move/Copy the sheets to a New Document.
There: you now have enough Google fodder to get you started.
I had this same issue a while back and found an excellent solution thanks to my good friend Google. All credit for this solution goes to the following page: computer hope
To merge Microsoft Excel files together, save them as CSV files first (it would be possible to automate this part in VBA if there is a recurrent need). Open the Excel files and in the menu bar, click File, then Save As. In the Save as type drop-down list, select CSV (comma delimited) (*.csv) from the list.
Do this for each Excel file you want to merge, then place all the CSV files in the same folder. For ease, place them in a folder in the root of the C: drive (e.g., c:\csvfiles).
Open the Windows command prompt (to get to this, in the Search or Run line, type cmd and press return) and navigate to the folder containing the CSV files. Type dir to view the files in the folder and ensure all the files are there.
Type in the following command to merge all CSV files in the folder into a new CSV file titled "newfile.csv" (any name could be used):
copy *.csv newfile.csv
After the new file is created, open the new CSV file in Microsoft Excel and save it as an Excel file.
Does anyone know what registry keys need to be modified in order to open macro enabled excel files in a separate instance of Excel (ie: separate windows)?
I followed the instructions on the following pages Microsoft How-To (if you want to open *.xlsx files in separate instances of excel)
and relation between registry folders and file extensions. The 'Microsoft How-To' link worked nicely and did exactly what it was supposed to do. However, I need xlsm files to open in separate windows and for the xlsx files to continue to open the default way (all in the same window/excel-instance).
I thought if i modified the Excel.SheetMacroEnabled.12\shell\open data (similar to what is described in the first link) the *.xlsm files would then always open in a new window each time.
Instead of this working successfully, now when I try to open an *.xlsm file, a blank excel window comes up with no workbook in it (after this failed attempt I imported the original settigs back so everything was restored).
Figure: I believe one of the folders shown in the image below has the key which needs to be changed in order to open excel macro files in separate windows.
You also need to delete the command REG_MULTI_SZ (the one with the seemingly gibberish-cryptographic value). Backup it in case it goes wrong!
Then, the XLSM files will open in a separate Excel program (notice the brief splash screen, which only appears when a new instance of Excel is created).
But be careful! In my tests, the order in which you open the file types make a big difference!
For example, if there is an Excel instance with a XLSM file open, and you open a XLSX file, it will try to reuse the existing Excel instance, because the registry associated to Excel.Sheet.12 tells it to do it no matter the file type already open. Only XLSM files opened after an existing Excel instance is running will create its own instance of Excel.
I will search for a workaround, but I think this is enough for you to start the tests in your computer.
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!!
I have created a hyperlink that connects to the files which exist in the same directory (or subdirectory) as the Excel file. How do I point to the file without setting the full path? The reason I don't want to give the full path is that if I moved the directory which contains other files and the Excel file to a different location, the hyperlinks shouldn't break.
I tried the option below, but the hyperlink only works if I don't move the files.
I want to assign the hyperlink an address like Example\IndexUsage_notes.txt instead of the full path D:\SCRIPTS\ADMIN_SCRIPTS\Example\IndexUsage_notes.txt
After searching online, I found this articles to be useful:
https://www.extendoffice.com/documents/excel/631-excel-file-location.html
This shows you how to get the file path of your workbook and how to isolate the main directory without using Macros.
Then you can insert your main file directory, sub-directory, and filename into the HYPERLINK function.
You can add text to the main directory using TEXT($B$1,0)&TEXT($B$2,0)&......
Dynamic Hyperlink Spreadsheet.png
Once the sub-directories are created and files are in place, you may not be able to move them easily without changing the sub-directory name manually within the spreadsheet or using Macros.