Browsing https SharePoint files and folders through local VBA - 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.

Related

Find and Replace to fix broken links

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

Google Sheets Security

I've been working on perfecting a couple of my google sheets for work. I need to share it with my coworkers, but I want to find a way to protect my hard work from being copied and repurposed by others.
They need to have edit access, so that eliminates "Disable options to down, print, and copy for commenters and viewers".'
I need to make sure this document doesn't get duplicated a dozen times by everyone the moment I provide them all with edit access. Any advice?
For any of those coming back to this feed, I've created a google script that if someone tries to make a copy of my document, the moment they open their doc, the entire sheet gets wiped (what I like to call 'self destruct').
So it is possible, despite the entire internet and google themselves saying it's not.

Custom Building Block Template wont load reliably

My small collection of document-specific macros and quickpart building blocks is growing! I'm starting to share these with employees, and am looking to be able to set up each remote computer once only. From there on, update collections on a network path. And because each computer looks to the shared location, everyone should always be working with up to date macros and quickparts etc.
So. What I already know:
- Required macros are saved in a separate module, ready to be shared/exported.
- Macros themselves occasionally reference local paths on my computer.
- I will need to reference paths with generic code or use Environ variables.
- Building blocks and quickparts are saved in a separate template file (currently located in Appdata, along with default building block file).
What I dont know:
a) How to point Word to a network path to retrieve macros from custom macro files. (Would I just have to import a fresh macro file at every important update, on each PC?)
b) What's the best way to load a building block item from a CUSTOM path?
My custom BuildingBlock template file is not loaded properly on occasion:
Dim objTemplate As Template
Dim objBB As BuildingBlock
'set template to store the building block
Set objTemplate = Templates("C:\Users\[USER]\AppData\Roaming\Microsoft_
\Document Building Blocks\1033\CustomBBlocks.dotx")
Set objBB = objTemplate.BuildingBlockEntries.Item("[EntryName]")
I know this because the code spits out a 'CollectionDoesntExist' error unless I click the Quickparts gallery prior to running the code for the first time. So it's like Word cant be bothered to open the template file and look inside unless I do it from the UI first.
Of course, if I first open the Quickparts gallery from the UI, prior to running my code, Word seems to figure it out, and inserts the correct Building Block entry without any issue.
In the past I've worked on a product that allows building blocks for Word too. Some sites have hundreds of templates and maybe 1.000 elements (see Composition). The approach we've taken was successful and was different.
You are trying to deploy software elements (macros) across a large number of workstations. You can try to get it working using the possibilities of Microsoft Word and Windows, but it will be sensitive to problems when things change. For instance, switching to Office 2013, splitting a domain into two, work at home without VPN, etc.
Option 1 - DIY deployment: Better put the macros and other stuff behind a webpage, webservice or alike. Deploy on each workstation a generic program that pulls in everything and deploys it locally. You might want to hand over some parameters to the webpage being called to restrict the amount of data. You might want to cache things locally.
Option 2 - Use ClickOnce: write a clickonce deployment script, include the necessary references and put it on a shared network drive or http address. ClickOnce automagically upgrades your software when it finds a new version. It even works across the internet. And it does nothing when there is no new version.
Option 3 - Database: put the elements centrally in a database, allowing end users to change building blocks through forms. Have Microsoft Word in combination with a ClickOnce program pull them in.
For Composition we've used option 2 and 3.

Changing the location of an existing VBA Reference from C:\Windows\system32\ to a shared drive

I've been trying for a while now to get a reference file to be loaded externally to no avail.
To be specific I am trying to load a "Microsoft Date and Time Picker Control 6.0(SP4)" which usually resides in C:\Windows\System32\MSCOMCT2.OCX
However some people that run a macro containing this element don't have that "MSCOMCT2.OCX" file on their PCs so I thought I will move the MSCOMCT2.OCX to a shared location and reference the code to use the shared one instead (so everyone will have access to it)
I tried doing that but when I was trying to load a reference with "Browse" from a different location it didn't load it - because I already had that in C:..
So I thought OK... I will remove the file from C:\ so I can only reference the shared file. - so I deleted it.
So I open the workbook again and look at references - I cant find "Microsotft Windows Common Controls-2.6.0(SP4)" - great!
And I proceed to add it manually with Browse from the shared drive.
When I do that however 2 references of "Microsotft Windows Common Controls-2.6.0(SP4)" are being added - 1 from C:\(which is not there) and 1 from the shared drive.
The one from C:\ is always automatically selected.
If I try to disable the one from C:\ and enable the one from the shared drive it automatically changes back to what it was when i press OK.
If I try to enable both - it says duplicate References and keeps only the one from C:\
So.. does anybody know how can I get rid of that C:\ reference from the list so it doesn't get loaded? Apparently deleting the files themselves did not work.
Ultimately my goal is to enable people without C:\Windows\System32\MSCOMCT2.OCX file to be able to use my Date Picker Tool.
Thanks a lot!
ActiveX control rereferences are always GUID-based. The VB IDE shows you the current location of the file as listed in the registry on your computer, as a courtesy, but it really doesn't matter what it says. The control will be loaded from wherever it was registered on the user's computer.
That's the key: the control must be registered on the user's computer.
I must strongly discourage you from doing what you're trying to do. You might be able to concoct a method by which you load the DLL from a network location, but it presents no advantage over doing the Right Thing(TM), and plenty of problems. The Right Thing is simply that if you need that control, you must distribute and register it with your application, just like everybody else does. And you really should install it in the recommended location for it (System32); not on the network.
Here's a quick example of what can go wrong: you provide your user with you app, and it works with the control on the network like you want it. Then the user installs another application that happens to need the same control. The app's installer sees that the control is already registered on the user's computer, so it doesn't try to add it again. Except that this particular app is intended to be used when the user is not connected to a network. Now you just broke someone else's program.
The VB/VBA architecture was never intended to support XCOPY deployment. I'm know it's a pain and that these extra steps are extremely inconvenient when you're just trying to deploy a "macro". Sadly, it's the nature of the beast. I'm sorry

Having trouble with buttons in mde file: list box .rowsource

I have a form that has a list box and several buttons that run sqk statements for the list box.
sub on_onClick()
' error checking
me.listbox.rowsource = "SELECT tblMain.First, tblMain.last FROM tblMain ORDER BY tblMain.Last;"
so this kinda thing is what I use for the list box. it works fine for me in the .mdb, and after i have converted the database, split it, made the .mde I go into the mde and it works fine for me still. This is placed on a shared drive
HOWEVER, anyone else that tries to use this, none of the buttons are having an effect. Can't tell if they are not working, or the VBA is not returning any results for them. It works for me, but it is not working for them. So...this is for my local LAN team, I think they all have full control permissions??? The button clicks that get them to that form are working fine also.
please help!
A couple of things come to mind:
It is not clear from your question whether the mde file itself is on a shared drive or whether the back-end database is on the shared drive and each user has a copy of the mde file on their PC. If the users are using the same mde file on the network share then I would strongly suggest not taking this approach. (It probably isn't the cause of the issue, but it will get you into trouble down the road.) Give each user a copy of the mde (front end) and have the application point to the back-end database on the network share.
Make sure that the mde has the ability to relink the tables to the back-end mdb file.If you search SO you'll probably find examples of how to do this in code.
I suspect you may be running into an issue where the mde file is not able to find the back-end tables. In this case you won't receive an error message in your VBA code when you're setting the listbox's rowsource and it will appear as though nothing is happening.
Do they have Macro security disabled? By default, MAcro security is enabled in Access and none of your VBA code will run. To disable: open Access, Tools -> Macro -> Security and set to low.
I think it is generally best to use self-certified projects or a secure location rather than change security levels.
Some information on macro security:
Self Certify projects
General information on security principals for Office code and macro security
Trusted location defaults for Office 2003
Macro security in Office 2003