Excel open same names files - excel

I need to create a button in Excel that opens a dialog box and I select the file that I recorded on the second sheet, but I also automatically select other files with the same name differs just ending. So I need to choose one file, and always record 2-3 more with the same name and to open a new worksheet. How to do it?
What you need to select the file abc.txt and uploaded to other files abc.ydd and abc.dyk name will always be the same only the ending will be different.

An advice for any work you are doing: Break down your big task into small steps as often as needed until the steps are small enough so that you know how to process them.
On your specific programming task, this means, you should break it down into:
You need a button on one of the excel sheets.
That button has to open a dialog box for selecting a file
I don't know whether it can be any arbitrary file or a specific one, as you wrote that the file was recorded on another sheet. I think that makes no difference at all.
After finishing the file selection, you have to evaluate the result of the dialog box (OK -> which file, ABORT -> do nothing).
Take the file name, remove the extension and search for other files (in the same directory or elsewhere) with that name.
I don't know why you want to open another worksheet. Of course you can do that, but if you want to show the content of that files in the worksheet, they better be excel files.
How you do these suggested steps is something you need to find out by yourself. Or you are lucky and find someone else who has plenty of free time to do that for you, but I don't think you will be that lucky, especially after providing a quite vague description of your problem.
In general, stackoverflow is for asking for solutions to specific programming problems, not for providing ready-to-use solutions for beginners. Take a look at VBA manuals and tutorials. They can be found widely across the internet and in book stores.

Related

PowerBI: Importing data from mixed folder files

I got a question related to the importing different files from the folder into Power Query (Power BI). When I say different, in my case are .xslx and .txt files. Actually just one text file but it is important to be inside report. Excel files are and will be always consistent as it is shown down in a first picture only with date as a dynamic part, but inside are consistently structured, so I just have to put it into folder and hit refresh into Power Query and magic.. that works fine, but I got also that .txt file which has completely different information but still connected to the report (because there is a field of date/time inside with additional information). My question is how or what is good approach to have all these files inside one or more queries?
As you can see on the second picture (from PQ editor) in the content part on the last position is .txt file, which I "isolated" when right click on it and "Add as a new query", and then I need to do editing and so on. Is there maybe another approach to solve this? One problem I discovered is when I change path of the file, all queries are refreshed but not this one with .txt - even though I changed path completely in the Advanced editor. Simply gives an error. Has anyone idea how to deal with different files from one folder, assuming that you need all the files from inside?
If you do not want 2 folders, your approach for isolating the txt is appropriate. about refreshing issues: if you expanded the data by clicking combine, Excel must have created other queries and parameters ("Sample from....") you must change the path in those queries too.

Excel hangs/crashes while updating external link at file opening

I encountered this weird ass and funny error.
I built a file for data ETL. This one takes in various .csv files, combines them and export new .csv files using VBA. The file is originally named as "xxx Modelling ETL.xlsm". It could be opened normally till one day it hangs or crashes while trying to recalculating something (may be the underground query).
After hours of struggling, I opened the file as a copy (under a new name of Copy of ...). Strangely it ran smoothly, no crash or hang. Then I try rename it by remove the "Copy of" part, then the error occurs again.
I want to share this as there could be someone has the same problem, or someone who could shed some light on this black magic thing.
Some solutions:
Rename the file or move it to local drive instead of Onedrive makes thing works normally again.
Open Trust Center, disable Macro with notification, Trusted Locations, and Trusted Documents. Enable them for specific files when open, not for all.

Prevent sending an opened excel document

Is there a possibilty to prevent a user from sending an excel document while it is still opened?
I had to make my document clear certain cells (containing personal data/personally identifiable information). I succesfully did this by using a function that generates a prompt before saving and only saves (and clears the respective fields) when accepting and doesnt do anything when canceling).
However, users can still send the opened document that contains the critical data.
I know it's a stretch, but is there a possibility to prevent this?
Like, with some sort of checksum/encryption shenanigans that corrupts the document while opened, thus rendering a sent copy in this state useless/not accessible/broken. The document would only be "fixed" again when saving (thus erasing the critical data too).
I can only imagine something like this, because forbidding other programs to read an opened excel document seems crazy.
Any help is greatly appreciated. Thanks in advance!
And hello to everyone here! (first post) This place is a lifesaver.
EDIT: For clarification:
1. Users get the excel document.
2. They enter personal data of staff/applicants etc. into it and my document does fancy stuff.
3. An output is generated which needs to go into some other tool.
4. The excel document's purpose is fulfilled and it must clean itself from filthy personal data.
This is achieved as described before. Saving etc. is all sorted out.
The problem I have been told to deal with, is to make it impossible to send the document while it still contains personal data. Closing wipes it, but while open, it still does contain personal data and can be interacted with Outlook etc.
Is there a way to prevent this kind of interaction with the document while still open? Or make the document corrupt while open, so copying it in this state won't transmit any personal data?
and welcome.
Your question is a bit of a strange one and I am not sure what would be the perfect way, but let me try answer and give you some suggestions:
A: You could work with a codeword in a specified cell. When you save a file it will put the word in that cell. When the word is not there.....well, let's say you can create some macro in Workbook.Open event that will delete all cellvalues and saves the file on its current location. Obviously put password on vba coding!
B: A more solid way in my opinion is to work on the file in your personal workspace if possible and upon saving the file create a copy to the shared folder through vba.
Good luck with it.
A: Manipulating the checksum/temp encryption would be quite risky since if your code crashes or is halted and closed the file is either corrupt or encrypted for you aswell, so information might be lost.
B: You could make the file copy to a temp while editing.
C: You can maybe block the save/autosave function of excel so that your editing won't get saved half-way in. (Not really a good solution, but a solution, likely quite easy).
EDIT:
For option C:
Insert this to workbook, it runs as it's named, before save.
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
//INSERT INSTRUCTION TO REMOVE PERSONAL DATA
End Sub
With this, data is removed before file is saved, so any saved state should be clean. Macro-deactivated workbooks however, cannot solve this problem, so you should maybe also add an event at workbook open that unlocks the sheets via VBA to avoid that flaw.

CSV to Excel Doc?

I was curious what the community thinks is the easiest way to take a CSV file and 'save as' a Excel document with only a couple formulas pasted in?
I am trying to do this behind the scenes, and not physically navigating. e.g. opening, selecting save As, etc -- even though this is already VERY simple I **need to do this in code (Think automation)
Background: I have a c++ command line program generating the .csv, and a C# GUI starting this process. Either programs could hold the code, but I figure this is easiest in C# (InterOp?) The reasons I don't directly send code into the csv is because of the amount of comma characters that will mess up the csv and because other Excel documents need to reference the sheets so they need to be in .xls format.
=AVERAGE(C2:C999)
=COUNTIFS(C:C,">0",C:C,"<31")
=COUNTIFS(C:C,">31",C:C,"<55")
=COUNTIF(C:C,">55")
Have a look and see whether command-line scipting of openoffice will do the job. It can do quite a lot of conversions very easily. Otherwise there are a lot of Excel-producing libraries, for example PHPExcel, but you'd need to wrap some programming around them.

Extracting a page from a pdf using a keyword

OK so im quite sure i cant do this with excel vb or for free even.
Im writing these macros for work, and one of them needs to be able to chose a pdf based on keywords.
Then go into the pdf, search either the titles of the pages or the text on the pages themselves using a different set of keywords.
When it finds the page that matches one of the keywords in the second set, it will extract the whole page, as is, to a single page pdf.
This can then be attached to email.
This will be only a small part of the purpose of the macro.
From what i understand, im probably going to have to find an SDK, pay for it, and write a separate program in C# or VisualBasic which is run when the macro needs.
I dont even need the code, maybe just a point in the right direction :D
In the end i got a program called pdftk.exe, free, and runs in command line.
With this i can export the Bookmarks listing to txtfile.
Search text file for string/keywords.
Jump down a line or two and grab associated page number.
Then use the same exe to extract that page and save as specific name, then my vba macro can grab that newly created 1 page pdf.
Ive seen code on this site for creating delays while another process is doing its thing, so i will try to implement that also.

Resources