How can I export a list from SharePoint to Excel, with header/footer/page orientation? - sharepoint

We would like to export a view of a custom SharePoint list to Excel on a repeatable basis, and with some minor formatting.
I have made a .iqy file by using Actions/Export to Spreadsheet from the view menu, and then uploaded this .iqy file back into SharePoint. When users click on it, it does bring up the data in Excel - but without the headings repeated each page, with the columns spilling onto a second page (width-wise), etc.
The .iqy file seems to be a plain text file which can be opened in Notepad so perhaps there is a way of passing parameters to Excel through this which would do the trick? Does someone know?
Alternatively, I also saved one of the resultant spreadsheets from opening the .iqy file, applied some formatting to it, and then uploaded that back into SharePoint. I set it to refresh the data connection on opening and I think this is working ok except there are two frustrations.
Firstly, by default, Excel says it has blocked data connections and I need to manually enable them. Is there a way to prevent this short of editing the trust centre settings on each computer that will open this spreadsheet?
Secondly, when I click on the spreadsheet in SharePoint we are asked if we wish to open the document for editing or read only. Ideally, I'd like to just give the user the opportunity to open or save the document (and certainly not to save it back on to the server, as I expect Edit would do.)
Does anyone have any sage advice for me that would make either the first attempt (.iqy file) or the second attempt (formatted spreadsheet) work successfully? Or maybe you have other, better ideas?
Thank you,
Regards,
David W

An Excel Web Query (iqy) is just not going to work. Its only purpose is to define a "web query" for Excel to open.
First frustration, I am not positive, but digitally signing the workbook may avoid the blocked data connection prompt. Also, if I remember correctly, there is a Global Policy setting for this, so if you are part of a domain, you can have this setting changed when the user logs into the domain.
Second frustration. Not much you can do here.
Suggestions, all kinds. We would need to understand your requirements and constraints. But, I suggest you dynamically create the workbook using XMLSS. You have full control over formatting, layout, and nearly everything else, without the need to have Excel installed on the server. The served workbook must then be saved locally and cannot be saved back to server.
See XML Spreadsheet Reference at
http://msdn.microsoft.com/en-us/library/aa140066(office.10).aspx
Here is a search for "visual basic asp xml workbooks site:microsoft.com",
http://www.bing.com/search?q=visual+basic+asp+xml+workbooks+site%3Amicrosoft.com. Search for ASP generates more results. Note it is easy to translate/migrate to ASP.NET so do not let the ASP throw you.
I recommend starting with Using Visual Basic and ASP with XML to Generate Excel 2003 Workbooks at http://msdn.microsoft.com/en-us/library/aa203722(office.11).aspx, especially near the end of the article because there is an example on creating a workbook and setting the page print orientation. Moreover, there is an example on how to create a template.

Related

Excel’s cursor/selection focus after inserting content add-ins

In Excel, I’m having my cursor/selection on a specific cell. Up until a recent Office update, the behavior upon inserting an Office.js-powered “content add-in” was like this:
The add-in is being inserted
The container of the web control is focused (you get the resize handles and Excel reveals the Drawing Tools menu) and the focus on the sheet is lost
getSelectedRange() right now would not yield any results but an error
You need to make at least one click into the web control’s area to de-focus the container and focus both the web control and re-focus the cursor/selection on the sheet
getSelectedRange() works now
After a recent update, I’m using Excel for Office 365 Version 16.0.11328.20362 now. And the behavior changed to this:
The add-in is being inserted — unchanged
The container of the web control is focused and the focus on the sheet is lost — unchanged
getSelectedRange() right now would not yield any results but an error — unchanged
Clicks on the web control don’t change the focus anymore, the container keeps being focused!
While the old behavior was already cumbersome as interaction between the add-in and the sheet was not possible directly after add-in insertion (only after at least one click), now not even the workaround of making that single click in the add-in is working anymore.
My original requirement was to read data from the sheet that has been selected just prior to inserting the add-in (just like it works with the native Excel charts). That’s why I had to come up with this one-click workaround in the first place.
What is now the best (if any) way to work with the workbook/sheet right after inserting the add-in with as few quirks as possible?

Why does the VBA Excel Addin code disappears and doesn't function after I close Excel and open a new Excel file?

I created a simple vba addin that colors cells based on their value, and I created a function that calls it with a shortcut then I saved it as an Excel addin and added it to Excel.
The problem is the addin works fine when I add it the first time, but when I open a new Excel file, I need to disable and enable the addin for it to work.
Update: I tried it on another computer and it works, but it shows an error that when I ignore it works fine. I am adding screenshots for the error and code
Error Message
Code
Sometimes, Excel will open workbooks in another Excel Application. This second application can sometimes face some issues with addins. You should double-check that the new file is opened in the same Excel Application. By looking at the task manager:
In this example, I'm using Window 10 and you can see that Book3.xlsx is in a different Excel Application than Book2.xlsx and Book1.xlsx
EDIT:
This question could also be of interest to you. The accepted answer reads:
This problem results from security patch in KB31152, released in July 2016. According to private communication with Microsoft software engineers:
"With this update, we changed the behavior of Excel so that it will
not load certain file types (including .xlam) when they are untrusted.
The easiest workaround is to find the add-in that is causing you
trouble, right-clicking on it in Windows Explorer, and checking
Unblock"
An easier approach is to simply place the add-in in a Trusted Location
(in Excel, go to File > Options > Trust Center > Trust Center Settings
Trusted Locations), such as the following folder, and load it from there:
C:\Users\%USER NAME%\AppData\Roaming\Microsoft\Excel\XLSTART
EDIT2:
And don't forget the option of just restarting your computer just to make sure that the problem is still there.

Opening Excel file from Sharepoint as Read-Write

I automatically open, edit, save and close several Excel workbooks from a Sharepoint location. The following code opens the workbooks (path loops through a list to hit each workbook name):
Workbooks.Open Filename:=path, ReadOnly:=False, Editable:=True
The files open in Read-Only mode, and the yellow dialogue option to Enable Editing does not appear.
I edit these workbooks manually and through a macro, but I am unable to save the files back onto the Sharepoint afterwards without saving as a new file.
I am using Excel 2013. This was working as intended about a year ago, but I believe there may have been updates to Office 365. I checked all of the Excel workbook security options, and nothing is set to open by default as Read-Only.
Is there any way to open the file in an editable mode through the macro, or at the very least allow the Enable Editing option to appear for each workbook?
I have been trying to fix the same problem for my files, and eventually did! So I felt that I could maybe let others know. And this old-ish thread came up near the top of my google search.
What fixed it for me was to edit the link.
from:
https://Company.sharepoint.com/:x:/r/teams/TeamNo/Shared%20Documents/Example/CoolFolder/TheBestExcelFile.xlsm
To:
https://Company.sharepoint.com/teams/TeamNo/Shared%20Documents/Example/CoolFolder/TheBestExcelFile.xlsm
Note that I only used replace to get rid of :x:/r/. I feel like I should have noticed this before but I didn't and no amount of meddling with the Workbook.Open parameters got me anywhere. It just seems odd that the default link copy thing gives you one with special commands in it. For our company most folders have spaces so the link has tons of "%20" in there so I simply read over the ":x:/r/".
Hope it helps someone.
Just for clarity, try this:
Sub Example()
'1.) Get filepath from somewhere
FilePath = Replace("https://Company.sharepoint.com/:x:/r/teams/TeamNo/Shared%20Documents/Example/CoolFolder/TheBestExcelFile.xlsm", ":x:/r/", "")
'2.) Open the file
Set StatisticsFile = Workbooks.Open(FileName:=FilePath, Password:="123")
'3.) Do things
'4.) Close the Sheet, save the changes. I simply like it this way, could be done in a single line.
StatisticsFile.Save
StatisticsFile.Close savechanges:=False
End Sub
I noticed this solution because I could still save the .xlsx file manually with the same name if I navigated to SaveAs. So if you guys can still do that after opening the file via macro, try a similar solution.
The interaction designed for Excel-OneDrive-SharePoint is new in 2016 apps and that version is a requisite to properly work.
The version 2013 may work by tweaking the OnDrive “Account” settings regarding Office co-authoring configuration which is specifically applied to Excel and Word
Right click the OneDrive icon in the taskbar to reach settings
Good luck!
I know your query was posted long ago but I have found the solution to remove the Read-Only blocker and update the excel document via Macro:
If you add "ActiveWorkbook.LockServerFile" after the code of opening the file, then it removes the Read-only and updates the excel as normal.

Excel Found Unreadable Content Error

I have been searching on the internet this error about excel.
"Excel found unreadable content in filename.xls. Do you want to recover the contents of this workbook? If you trust the source of this workbook, click Yes."
When I go to Microsoft Support website, I saw this solution
http://support.microsoft.com/kb/929766/en-us
In this page it says "To resolve this issue, remove the expressions from all Current Time Member and weight on the KPI properties." I did not understand what to do exactly. Please help me
This is an old question but I wanted to say that. There are lots of ways which you can see this error. Firstly, your computer's clock. you should set it to your terratory. Secondly the Excel version. You should use a formal instance of Microsoft Excel. If you do not want to deal with Microsoft, LibreOffice is free and full of good features. You should try that.
Click yes, save under a new filename, and check the contents match what you expect. If you're able to restore using "Restore previous versions" (right click on the file in explorer) then that's an option as well.

What is the best way to package and distribute an Excel application

I've writen an Excel-based, database reporting tool. Currentely, all the VBA code is associated with a single XLS file. The user generates the report by clicking a button on the toolbar. Unfortunately, unless the user has saved the file under another file name, all the reported data gets wiped-out.
When I have created similar tools in Word, I can put all the code in a template (.dot) file and call it from there. If I put the template file in the Office startup folder, it will launch everytime I start Word. Is there a similar way, to package and distribute my code in Excel? I've tried using Add-ins, but I didn't find a way to call the code from the application window.
Simply move your code into an Excel Addin (XLA) - this gets loaded at startup (assuming it's in the %AppData%\Microsoft\Excel\XLSTART folder) but if it's a addin, not a workbook, then only your macros and defined startup functions will be loaded.
If the functions depend on a spreadsheet itself, then you might want to use a combination of templates and addins.
I'm distributing part of an application like this, we have addins for Word, Excel and Powerpoint (XLA, PPA, DOT) and also Office 2007 'ribbon' versions (DOTM, XLAM and PPAM)
The addin startup code creates toolbar buttons if they're not found, this means in any workbook/document/etc they can simply hit the toolbar button to run our code (we have two action buttons and one button that displays a settings dialog)
Templates aren't really the way to go for VBA code, Addins are definitely the way to go...
So to load the toolbars on startup we're using something like.. (checking to see if toolbar exists though - code will run for each worksheet that is opened, but toolbars are persistent for the user session)
Public Sub Workbook_Open()
' startup code / add toolbar / load saved settings, etc.
End Sub
hope that helps :)
I always use an Add-in(xla)/Template(xlt) combination. Your add-in creates the menu (or other UI entry points) and loads templates as needed. It also write data that you want to persist to a database (Access, SQLServer, text file, or even an xls file).
The first rule is to keep your code separate from your data. Then, if you later have bug fixes or other code changes, you can send a new add-in and all of their templates and databases aren't affected.
You can modify the user's personal.xls file, stored in the excel startup directory (varies between Office versions). If you have lots of users though, that can be fiddly.
An alternative way to get over your problem is to store the macro in a template (.xlt) file. Then when the users opens it they can't save it back over the original file, but have to specify a new filename to save it as. The disadvantage of this method is that you then get multiple copies of your original code all over the place with each saved file. If you modify the original .xlt and someone reruns the old macro in a previously-saved .xls file then things can get out of step.
Have you looked into ClickOnce deploying the Excel file?
What about to save an excel to network folder with read only permissions ? The authentication can be done with integrated windows authentication and you don't need to store connection password to the database in the VBA. Then you only need distribute a link to this location to your users only once. If you will do an update, you only change data in that folder without user notice.

Resources