Find and Replace to fix broken links - vba

I am new to VBA and learning a ton using these forums but I am stumped on how I should tackle this problem I am coming across.
The Problem:
I am setting up VBA for our workplace physical inventory that we do 1 time per quarter. I have so far got my code to create a new folder based on today's date, and then the code will copy and paste all the files and subfolders from the master folder into this newly created folder. The issue I am having is that the excel file we use for our physical inventory, is linked to various other excel workbooks (which can be found in the sub folders under the master folder), so when the code copies and pastes the files, the file paths change and break the links to the various workbooks. Ideally, I am just trying to get my code to find and replace the existing "master template" folder path, to the newly created folder path as mentioned above. That way, all that needs to be done is to click the button that creates the new physical inventory folder with the master templates, then it will find and replace all existing external paths, with the new folder path to enable the links to continue working. If one of you master excel wizards would be so kind to help a rookie out, I would greatly appreciate it. I am not at work now, but I can provide the VBA code I have created thus far tomorrow. I am also always open to new ideas as to how I can do this in a simpler manner if find and replace isn't necessary. I have tried to do fix links command and that doesn't work without having to go through each workbook and manually changing path locations.
Thank you once again for all your help.

if code is not needed, there is a free tool that I came across which removed all broken links in the Excel workbook:
https://youtu.be/FyCNWE3_YpY

Related

How to Create a Program Which Searches for Values from a .txt or any Text Document in Specific Folders

I am relatively new to programming and want to create a program which can solve a problem that I frequently have.
So here's the background to my short story: I was on a website which hosted many files (We're talking about around 500-1000 small files). I was then like," Oh sweet! I want to have all these things in my hard drive so I know that I have access to them... but am probably not going to use them either way". I proceeded to download all 500-1000 files on that site, but encountered a problem when I looked at the properties of my destination file. Let's say that out of 500 on the site, my computer only had 499 files. Just my luck. I wanted to know what was that one pesky file that slipped right by me and download that file specifically. What I didn't want to do was to delete all the files and then try my luck once more in downloading all the files from the website. On the site, there was no indication of what all files I downloaded, so I was completely in the blue. I could go in Ctrl+C each item, then Ctrl+V into the file manager search bar, but that would be tedious to repeat that 500 times.
Now, what I want to do: I wanted to go ahead and take all of the file names from the website (The file name that I downloaded and the file name that was in my drive are the same), put them all in a simple .txt document or something (The website has multiple unwanted text alongside the text I need, such as:
. If this is not possible to extract the text from the site like this, then I am ok with manually entering the names via copy paste). Then I want the computer to take these values in the document and then search for it in a specific folder path (Note: the actual files are in subfolders within the root folder I want to choose, so the program has to be able to search within multiple folders of the root). Then I want the computer to know if the value in the document, is present as a file. If the file doesn't exist, then I want that value/those values in the document to be displayed as the output. I want this cycle to repeat until all the values have been gone through. The output should list the values that were not present.
Conclusion: You probably now get at what I am trying to do, if you don't, tell me what I need to elaborate on. I really don't care how this program is made (what language or software), I just want something that works... but myself don't know how to create.
Thanks for reading and any response is appreciated!
Dhanwanth P :)
Here's a solution in Python in case you would like to explore...
Similar to what you described, all files from the website are listed in an Excel file 'website_files.xlsx'
And all files are saved in a folder 'downloaded_wav'. The script will work regardless the files are saved in the root directory or sub-folders.
Then I run below Python script to look for the missing file:
import pandas as pd
import os
path_folder = 'C:\\Users\\Admin\\Downloads\\downloaded_wav'
downloaded_files = []
d,m = 0,0
for path_name, subfolders, files in os.walk(path_folder): #include all subfolders
for file in files:
d+=1
downloaded_files.append(file)
df = pd.read_excel('website_files.xlsx')
for file in df.values:
if file not in downloaded_files:
print('MISSING', file)
m+=1
print(len(df), 'files on website')
print(d, 'files downloaded')
print(m, 'missing file(s) found')
Output:
MISSING ['OLIVER_snare_disco_mixready_hybrid.wav']
3 files on website
2 files downloaded
1 missing file(s) found
No worries; I found a solution by myself using Excel (God, it's powerful!).
Basically, I copied and pasted my values from the website, then used a filter to show the values only with .wav. Then I used a Power Query from the folder to get me a list of all names of files in a folder. Finally, I went ahead and compared the two using a formula:
=IF(COUNTIF(B:B,D,"OK","MISSING")
If you need more elaboration, I'd be happy to help, just reply to this. There might be an easier way, but I personally liked the straight-forwardness of this. You only need Microsoft excel!
EDIT:
For me, I used these two videos which go over the power query and countif function:
How to Get the List of File Names in a Folder in Excel (without VBA): https://www.youtube.com/watch?v=OSCPVBWOqwc
How to Compare Two Excel Sheets (and find the differences): https://www.youtube.com/watch?v=8Ou_wfzcKKk
In my case, I made my sheet look like this:

VBA Excel lookup same value in different excel files

Would like to check the value from my master file and copy the data comments from different excel files.
In my master I have a column contained all the user name. Would like to copy the address of the user from different excel file. Would like to open the workbook and look through is the user name in the workbook, if not then then exit and open another workbook.
How should I complete the flow ?
Unfortunately StackOverflow is not a free coding service. Our goal is to help you understand how your code works and engage the community with questions that will also help others in the future. Try running some of the code on your own and see what you can come up with. There are hundreds of sources online, one of my favorite being "Excel Easy", a website that breaks down VBA coding to its simplest form. Check it out and then after you've given it a go yourself feel free to ask any specific question about your code!

Excel cannot find my Macro

I have a Worksheet.Activate macro for pasting information that has been working for over a year now. I have multiple users using the macro with no problems. Recently one user is having this error whenever they paste into this worksheet that activates the macro:
Run-time error '1004': 'C:\Users\xxxx\Documents\Master_Macros.xlsb' could not be found. Check the spelling of the file name, and verify that the file location is correct.
They have never had this issue before and as far as I know he hasn't done anything abnormal. The macro is located in the typical XLSTART folder, not the Documents folder. The macro file also includes other macros that are executing perfectly fine for this user. Excel is suddenly looking for the macro file in the Documents folder for this one Worksheet.Activate macro. I have spent some time googling, and I don't know if it is my keyword choice or what, I cannot find a solution.
The macro is run using this line:
Application.Run ("Master_Macros.xlsb!'C_Tool_Paste_Window.CTool_LineFix'")
Any help would be appreciated!
I had similar problem when I installed Service Pack.
If the users are accessing files from different computers,
make sure they all have same service pack installed

Browsing https SharePoint files and folders through local VBA

I've searched around for some answers to this, but nothing I found seemed to work. I'm good with VBA, but Sharepoint is not my cup of tea. We have a corporate Sharepoint site on the web (https) where different regions submit metrics using Excel. Each Excel file is placed in the region's respective folder.
What I want to be able to do is use a local workbook to navigate to the Sharepoint site, go through the folders, open each Excel workbook, and aggregate the numbers together. The closest I've come so far is this.
However, let's say my site is:
[https://teams.mycompany.com/SubTeamFolder/Forms/AllItems.aspx.]
Nothing gets returned when I set the site variable to this in the code from the link above. If I set the site variable to something like:
[https://teams.mycompany.com/SubTeamFolder/AllItems/]
it throws error
-2147217895
.
I'm open to other approaches here. Like I said, this one seemed the most promising till I hit this wall.
Just as an FYI for those who come across this, here is how I worked through this. In the link submitted by #ARich, I went towards the bottom and used the Export to Excel functionality. This let me see the underlying path for my objects. I was then able to use the code I linked to in my original post to see the underlying folders. If you need to, insert a couple of breakpoints once you successfully connect to your target Sharepoint site to follow along with the recursive movement from parent to child object. Taking it a step further, you can then open the files using this.

Moving subproject files and updating links in master project

I am working in MS Project and frequently move schedules from a share drive to my computer, manipulate and run macros on them, then copy them back up to the share drive.
Generally if I copy all of the subprojects with the Master project at one time the links to the subprojects will update to the destination folder (the one on my computer.) Occasionally I do this and the links do not update, so the Master Schedule is still pointing to the files on the share drive. This causes problems with the macro I then run on it. I have not been able to find anything in forums about this problem.
Has anyone come across this problem? Is there a setting somewhere that is getting changed? Any help would be appreciated.
Yes, I've come across this problem.
The most reliable way of copying a master schedule and all it's sub projects without creating the duplicate links is to:
Select all the files on the share drive
Right click and send them to a zip file
Move this zip file to your local drive
Right click on the zip file and extract all
Then do the same in reverse once you've run your macros. This should reliably copy the master/sub project files with the correct links, without creating the erroneous links you've seen.