Power Query: Get Data from an online Excel workbook (OneDrive, SharePoint) - excel

I've asked this before, and I think I got some comments on the question not being specific/researched enough (I'm new here!) So I'm posting again, with a bit more research. Apologies if there is still anything missing:
I need an Excel workbook to get data from another Excel workbook that lives on OneDrive. I want to share the mirror workbook with other coworkers so they can reference it.
As I have it now, on my OneDrive folder in my computer I created the mirror workbook and got data from the master workbook (also in my OneDrive folder). Lastly, I have shared the mirror workbook though OneDrive with a coworker. However, when I test opening the workbook from the coworker's computer, the workbook is still referencing the file path as if it were in my computer where I created the query and the workbook files.
As I understand it, instead of a file path, the workbooks needs a URL to reference the master workbook that lives in OneDrive (which I don't want to share).
I've tried generating different share links from the OneDrive web portal but nothing seems to access. I get access denied messages.
A bit of background, everyone has their own 365 account. And I am doing everything from the app. Not using the browser version of Excel a ay point.

I've done SharePoint before using the SharePoint folder data connector. To do this, select that connector option, paste in the site URL (e.g. https://company.sharepoint.com/sites/GroupName/), and use Microsoft account as the authentication method.
Example M query:
let
Source = SharePoint.Files("https://company.sharepoint.com/sites/GroupName/", [ApiVersion = 15]),
#"Excel File Name" = Source{[Name="Excel File Name.xlsx",#"Folder Path"="https://company.sharepoint.com/sites/GroupName/Shared Documents/General/"]}[Content],
#"Imported Excel" = Excel.Workbook(#"Excel File Name"),
#"Sheet Name_Sheet" = #"Imported Excel"{[Item="Sheet Name",Kind="Sheet"]}[Data]
in
#"Sheet Name_Sheet"

Related

Linked Excel file opens when Access front end opens- How to stop this behavior

I have Ms access- frond end which is distributed to more than 50 Users and its works very well until today i come across a weird behavior.
today, I have linked one excel file in back end and use this linked table in front end a create a form using query (view only) and updated my front end. through my test I found that if I open two instance of my front end and open the newly created form than in second instance access open my the linked Excel file as readonly.
My question is, how can i avoid this behavior? I don't want my users to see this excel file by any way. is there any work around?
That's by design. An Excel workbook hosted on premise cannot be shared for writing.
One workaround is to create a copy of the workbook for each user. For instance, let your application copy the workbook from the shared location to a local subfolder of %LocalAppData%, the user's local data folder, and link to that.

Unable to determine why workbook gets marked as read only when opening another workbook via VBA

Background: I can't seem to find an answer for the blunder I've found myself in. I'm working on a dashboard of sorts for our organization that pulls data from different workbooks in different locations. Different people have different permissions within folders in our company. We're trying to prevent having to change permissions. I was also trying to make it easy as possible for employees by moving the necessary supporting files I pull from to my folder where the dashboard is housed that includes a folder with the supporting files. Since this folder has no restricted access, I added passwords to the whole workbook of each supporting file. I created workbooks in the original locations of where these supporting files used to reside with the hopes that would hopefully allow anyone with access in that folder to use this new file as a backdoor/shortcut of sorts. The goal was to keep people's files where they wanted them and allow them to click it then it takes them to my support file and enter the password for them. Which leads me to the problem...
Problem: When I open the "backdoor" file, everything runs normally and the support file opens up with read and write privileges. However when someone else opens the backdoor file, the support file opens as read only. While I don't have any code yet to determine if someone is in the file (I'll cross that road if my problem is resolvable), I've ensured nobody was in the support or backdoor file when another user attempted to use it.
Sub Workbook_Open()
'I didn't have the next statement orginally. Added it in hopes it'd resolve the issue.
'Tried to move it under the workbooks.open command, too, but to no avail.
SetAttr "M:\Report Writing\Supporting Files\TMR 2017 - Team ABC's SF.xlsm", vbNormal
Workbooks.Open "M:\Report Writing\Supporting Files\TMR 2017 - Team ABC's SF.xlsm", , False, , "XXX"
Workbooks("TMR 2017 - Team ABC's.xlsm").Close
End Sub
I also didn't originally have the "False" in the open.workbooks command but tried to add it in hopes of resolving my dilemma. Any hope is GREATLY appreciated as my whole dashboard is relying on this and we were supposed to deploy today.
It has nothing to do with the VBA code. It is the file itself. On a shared network, depending on how it was set up, when a new file is created everyone can read it, but only the creator is marked as the only one allowed to make changes. If someone Saves the file with another name you wont be able to edit it. You created the file, you can make changes to it.
There is a way to change this. Right click on the file, properties, security, Edit Button, There are some listed users in there but just find the one that says Drive\Users or Authenticated Users, or both, and edit that to provide modify access. This will allow everyone to edit the file.

Workbook.SaveAs Sharepoint Integration

I have developed an Excel file that contains a button with a macro that will save the workbook for the user. This has worked well until recently when we are migrating to Sharepoint and users are trying to save the workbook to a mapped drive that is mapped to a Sharepoint location.
So, for example, my user has \\<server#SSL\sites\<sitename>\<documentlibrary> mapped to her Z drive.
When I use ThisWorkbook.GetSaveAsFilename the result returns a url like so https://<server#SSL\sites\<sitename>\<documentlibrary>\<filename>.xlsm
Before making any changes, I was getting a run-time error on the line
ThisWorkbook.SaveAs Filename:=excelFile
where excelFile is https://<server#SSL\sites\<sitename>\<documentlibrary>\<filename>.xlsm
My first attempt was to do some find/replace on the string. First replacing https: with nothing and then replacing the forward slash / with the backslash \ to make it resemble a file path like so:
\\<server#SSL\sites\<sitename>\<documentlibrary>\filename.xlsm
There was some progress made here. I received no VBA error, however I did get a message:
UPLOAD FAILED We're sorry this didn't work. Try saving again later
and if that still doesn't work, click Save a Copy
and I see the file attempting to be uploaded in the Microsoft Office Upload Center, so this is progress.
I can't seem to make it around this upload failure message.
I have tested that my permissions to the document library are sufficient by manually uploading the file that I am attempting to automatically upload.
So, how can I use ThisWorkbook.SaveAs to save a file to a Sharepoint document library?
I am using Excel 2013 and Sharepoint 2013.
While I cannot explain it, after some tinkering around, I believe I have found the solution.
Changing
ThisWorkbook.SaveAs Filename:=excelFile
To
ThisWorkbook.SaveAs fileName:=excelName, FileFormat:=xlOpenXMLWorkbook, ConflictResolution:=xlUserResolution
Seemed to make it work.
I explicitly set the FileFormat and ConflictResolution arguments and the user is able to save.

Creating a C# program that works with an existing Excel Workbook

firstly I'm not even sure if its even possible so i thought id ask
all research that i have done haven't given me the answers and info I need.
I need to create a VS Win forms program (using visual studio 2012) that interacts with a DB & AN EXCEL 2010 WORKBOOK?
can it be reasonably done?
the specifics are these
the excel 2010 workbook already exists and comprises 35 sheets/pages, BUT NOT ALL PAGES NEED TO BE USED IN THE PROGRAM only 12 do. it is a workbook for project management
the program works with button click events, that when pressed would open a specific page/sheet of the workbook. the user would then be able to fill in fields etc and save it
ideally also print it(Specific page) (from program and not excel directly) and obviously access it and amend or add to it from the Program time and time again
the workbook is a master workbook so every time a new project is created, the program would need to generate a new "instance" of the master workbook (the 12 pages)
each project and the "instance" of the workbook would need to be saved separately on the Hard Drive
this is/would be a client side stand alone application running on a laptop
is this possible? or highly complex?
and if so what are the relevant classes that would need to be imported into the project
or is it better/possible? to take the relevant pages ad make a new workbook inside of visual studio office node and make instances of it ??
at no point at all does data in the DB or Excel workbook need to be transferred to one another. they run separately but are part of the one program
any and all help would be appreciated
This is not a complex project, visual studio supports Microsoft Excel 12.0 Object Library. You can import the library and start using the events built in. It works great with excel. I have created numerous projects just like the one you've mentioned and had no problems so far.
Try this link

Open Excel workbook as read-only via VB6

I have an application written in VB6 that writes data to a spreadsheet. I'm using the MS Excel 11.0 Object library to create an instance of Excel and open the book:
Dim xlApp As Excel.Application, remoteBook As Workbook
Set xlApp = New Excel.Application
Set remoteBook = xlApp.Workbooks.Open(sheetName)
In addition to writing to the workbook "sheetName", the program also allows the user to launch the workbook in order to view the cumulative results.
There is a chance, however slim it may be, that a user could have the workbook open for viewing the results while someone else is trying to write to it. I want to give the user writing to the sheet priority. Is there a way I can launch the sheet for viewing as read-only? There is a read-only property of the excel application object, but it is (of course) read-only.
How can I set up my program to write data to the workbook even if someone has accidentally left the file open at their desk?
Simply do this:
Set remoteBook = xlApp.Workbooks.Open( sheetName, , true)
Where true is whether or not to open as Read Only. ReadOnly is the third parameter to this method.
I think you might be able to do it via the Workbook.ChangeFileAccess method as described here. Not sure if it will suit your circumstances though.
Let me make sure I have properly interpreted your issue:
Your app writes an excel file
The App launches the file in Excel
to the User
Now here's what I think you're saying:
Once the user is viewing the sheet, they may or may not want to edit that sheet.
In other words, you don't want to use
Set remoteBook = xlApp.Workbooks.Open( sheetName, , true)
100% of the time because the user viewing may want to change the data.
The downside is that this dastardly user may leave the file open to prevent other users from writing to that file.
Is that correct?
If so, it sounds like you may need to explicit state in your app to "Open for viewing" or "open for read-only" access and then toggle the Read Only property appropriately; which is probably undesirable.
However, you can't force a save on an office doc once someone else has it open.

Resources