Error 70 in Excel VBA - excel

I am trying to upload directly a picture/chart from excel to a Sharepoint group URL. Here is the script:
Sub ExportChartJPG()
ActiveChart.Export Filename:="http://sharepoint.ap.xxxxxxxxxxxxxx.com/xxxxxx/xxxxxxxxxxxxxx/Pictures/MyChart.jpg", _FilterName:="jpeg"
End Sub
Is that possible? If it's not then can you suggest another way of doing it? Thanks

You can only export to a file, not to a URL. So, you could export to a temporary file on disk, and then submit the file to your web server. You would of course need the web server to have the ability to receive files.
Hang on, from the URL, it's a SharePoint server, yes? Presumably a SharePoint document library? In that case, you need to write some code to use one of the following techniques to upload the file:
SharePoint Web Service
WebDAV
FrontPage Extensions
If you want to do this in VBA, then the MSXML3 library may be useful, since it will let you do HTTP requests.
EDIT: OK, based on your comments, here's a simple VBScript script to get you started. This opens an Excel workbook at a known location, and exports the first chart sheet.
Save this as "test.vbs" and then double-click on it to run it (having created a suitable Excel file, etc.).
Dim oExcel : Set oExcel = CreateObject("Excel.Application")
Dim oWorkbook : Set oWorkbook = oExcel.Workbooks.Open("C:\test.xls")
Dim oChart : Set oChart = oWorkbook.Charts(1)
oChart.Export "C:\chart.jpg", "JPEG"
oWorkbook.Close False
oExcel.Quit
As I said in my comment, VBScript is very much like VBA, but the downside is that there's no strong typing, so you don't get Intellisense, etc. It might be easier to create the script in VBA where you do have Intellisense (and a debugger, etc.) and then "port" it to VBScript.

Related

Excel 2016 file ignoring links and grant access using applescript

The problem i am having is that i am always receiving new spreadsheets and if i run the code below.
set resultWorkBook to "/Users/x/Desktop/myfile.xmls"
tell application "Microsoft Excel"
set resultWorkbook to open workbook workbook file name posix_file without update links
end tell
It will try to open the spreadsheet but then come up with the dialog window asking whether to grant access or not.
If I run the same spreadsheet like this.
tell application "Finder
set filecontents to file of folder Desktop of (path to home folder)
end tell
tell application "Microsoft Excel"
set display alerts to false
set resultWorkbook to open filecontents
end tell
It will open the workbook without asking for access but then comes up asking me to choose one of three options regarding links in the spreadsheet.
I really need the best of both worlds, and wondered if anyone could give me a solution.
Thanks
Just convert the posix path (a string) to a file object, like this
set posix_file to "/Users/x/Desktop/myfile.xmls" as POSIX file
tell application "Microsoft Excel"
set resultWorkBook to open workbook workbook file name posix_file without update links
end tell
Update; the difference is the as POSIX filecommand.

Set Sharepoint Tags/Properies with VBA

Is it possible to set the Tags of a Sharepoint document (specifically Excel) using VBA. At present the only way I know to handle this is to save a file to Sharepoint, set the Tags when prompted, nd then download this file again and use it as a template.
However, I need to work with several different permuations of these Tags and it's a major pain having to create a separate template for each one, especially if you then need to amend the template, and have to replicate those amendments 10s of times.
So is it possible to do this via VBA? I've tried recording a macro whilst I set them and it doesn't record anything regarding the Tags
As far as I know , we can set the Tags of an Excel document in VBA before it gets uploaded onto a Sharepoint library,
by settings values for the
Workbook.ContentTypeProperties
For example:
ActiveWorkbook.ContentTypeProperties("Line of Business").Value = pLine
ActiveWorkbook.ContentTypeProperties("Company Name").Value = pCompany
ActiveWorkbook.ContentTypeProperties("Year").Value = pYear
I'd link some readings to learn more: It might be useful:[John Chapman's SharePoint Blog: Update SharePoint Document Property from Excel VBA]
http://www.sharepointjohn.com/sharepoint-2007-–-update-sharepoint-document-property-from-excel-vba/
Please note that there are some troubles with certain types of property: see
Setting Custom Document properties that will be used in Sharepoint and this thread
I had the same problem. The workaround I used was as follows
On Error Resume Next
Application.DisplayAlerts = False
ThisWorkbook.SaveAs Pth
ThisWorkbook.ContentTypeProperties("Report Type").Value = "BranchManagement"
ThisWorkbook.SaveAs Pth
Workbooks(ThisWorkbook.Name).CheckIn
Application.DisplayAlerts = True
On Error GoTo 0
In my case I also had to check the book in after getting it saved. Hope this helps!

How to create real excel file in Classic ASP

I have been exporting excel files using application/vnd.ms-excel option in classic ASP but after downloading when I click Save As I see Save As Type option = web page.
So is there any way to Save As by default so the file type can be saved as an "Excel 97-2003 WorkBook"? I tried excel.application and owc but unfortunately neither work for me.
Actually, these options are consuming a lot of CPU memory when I use them.
I am open to using any third party component for excel creation.
Thanks.
I am not sure if you are aware but you can access the Excel DOM using classic ASP as long as you have Excel installed on the web server.
There are limitations to what you can do but if your requirements are simple then it might be the answer you are looking for without the need to purchase expensive components which are starting to become unsupported.
Set oExcel = Server.CreateObject("Excel.Application")
Set oBook = oExcel.Workbooks.Add
Set oSheet = oBook.ActiveSheet
Set oRange = oExcel.ActiveCell
oRange.Cells(1,1) = "First Column"
oRange.Cells(1,2) = "Second Column"
oBook.SaveAs "workbook.xls"
oBook.Close
oExcel.Quit
Set oExcel = Nothing

INsert value with Asp to excelsheet and call function?

I've got a real problem..
I got an webpage writen in traditionel Asp. What i need to do now is to insert a value to a field in a excelsheet. The thing is that the excelfile also contains som sub routines and i also what to call one of thoose routines after i inserted the value in the field.. Is this even posible?
Best regards
It's all possible (although you may have problems with security in automating Office from ASP, since the IUSR user generally does not have permission to do much), but it's not a great idea, since Office is not designed to be used in a multi-threaded / multi-user environment. If this is for an intranet, then it may be OK. If it's for a public website, I'd suggest finding some other route.
Those issues aside, driving Excel from ASP is no different from driving it from VBA, VBScript or VB. You can open workbooks, make changes, even call methods defined as VBA within the workbook. For the latter, use the Application.Run method.
EDIT: some sample code (from memory - may be full of syntax errors!)
Set oExcelApp = CreateObject("Excel.Application")
Set oWorkbook = oExcelApp.Open("file.xls")
Set oWorksheet = oWorkbook.Worksheets(1)
oWorksheet.Cells(1,1).Value = "foo"
oExcelApp.Run "'file.xls'!macroname"
oWorkbook.Save
oWorkbook.Close
oExcelApp.Quit

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