Uploading Excel file using VBA to SharePoint - excel

Im struggling to resolve an upload problem direct from excel to sharepoint. I have the right permissions and can upload no problem when hardcoding the URL. Issue I have is all the SharePoint URL's are by Project Number and Description for example:
https://teamzzz.sharepoint.com/sites/Projects/NL001%20%20TEST/10.%20Dispatch
The project is called NL001 in this case. Another example of a URL could be:
https://teamzzz.sharepoint.com/sites/Projects/ZNP001%20%20ANOTHERTEST/10.%20Dispatch
Basically at the point of attempting to upload using my Add in I know the first part of the PATH:
https://teamzzz.sharepoint.com/sites/Projects/
The project id I can find from a cell reference:
NL001
The last part of the URL will always be the same as in:
10.%20Dispatch
My problem is the description after NL001 i.e. "%20%20TEST" (see below):
https://teamzzz.sharepoint.com/sites/Projects/NL001%20%20TEST/10.%20Dispatch
Is there anyway I can use some form of wildcard in the URL for example:
https://teamcde.sharepoint.com/sites/Projects/NL001*/10.%20Dispatch
OR
https://teamcde.sharepoint.com/sites/Projects/NL001%/10.%20Dispatch
The above 2 example dont work but was demonstrating the example I require. Here is my code thus far:
Public Sub CommandButton39_Click()
ProjectFileName = Range("B2").Value
SharePointBasePath = "https://teamcde.sharepoint.com/sites/Projects/"
SharePointEndPath = "10.%20Dispatch/"
ActiveWorkbook.SaveAs Filename:=SharePointBasePath & ThisFile & ".xlsm" & SharePointEndPath
End Sub
Is is possible to utilise a wildcard as the description is not known at time of upload.
Thankyou

Related

VBA script issue specifying command line

So I'm fairly new to VBA, using it within some spreadsheets so forgive me if this is a super obvious fix, I'm sure it is but have spent hours on with with no success.
The following piece of code will lie inside of an if statement - not sure if thats worth mentioning or not.
I want to simply move, and rename files from one location to the other
It needs to utilize cmd.exe, and use the 'move' argument - the source path and source destinations will be changeable depending on the pc - so it will need to use the '%temp% - as the initial file will be stored in this folder, and %userprofile% for the destination path.
Here is the code so far - I think the issue is just to do with the formatting -
Sub movefile ()
Dim Origpath As String
Dim NewPath As String
OrigPath="%temp%\newfile.txt"
NewPath="%userprofile%`Documents\newfile.vbs"
<<next code inside of an if statement>>
moveFile="C:\windows\system32\cmd.exe /C move " & OrigPath & " " & NewPath
End Sub
Maybe the " and & arent placed correctly? But the code works fine up until the line 'movefile...'
Probably a super easy way of doing it - help please!!
Try using Name:
name OrigPath as NewPath
Alternatively you can use use fdo movefile, as explained in this answer.

Adding this URL from JIRA as hyperlink to the excel cell does not work, why?

I have the following link:
https://nttdata.atlassian.net/sr/jira.issueviews:searchrequest-csv-current-fields/temp/SearchRequest.csv?jqlQuery=project+%3D+ATHP+AND+issuetype+in+%28story%2C+feature%2C+task%29+AND+Sprint+%3D+1113+AND+%28status+was+not+in++%28DONE%2C+%22BUILD+COMPLETE%22%29+AFTER+%222019%2F01%2F21%22+%29+AND+%28status+was+not+in++%28DONE%2C+%22BUILD+COMPLETE%22%29++BEFORE+%222019%2F01%2F23%22%29&tempMax=1000
Note: It assumes to have an open Jira session for this project. I provided it here in case there is some special character that excel may interpret in a different way.
It executes a Jira Query and downloads the result in a CSV file.
This query is generated by JIRA when trying to export into an excel file the result of the Jira Query Language:
project = ATHP AND issuetype in (story, feature, task) AND
Sprint = 1113 AND (status was not in (DONE, "BUILD COMPLETE") AFTER
"2019/01/21" ) AND (status was not in (DONE, "BUILD COMPLETE")
BEFORE "2019/01/23")
Note: I was trying with a simpler query too based on JIRA request: project = ATHP (search for all issues of project with ID: ATHP) that produce the following query:
https://nttdata.atlassian.net/sr/jira.issueviews:searchrequest-csv-current-fields/temp/SearchRequest.csv?jqlQuery=project+%3DATHP&tempMax=1000
with the same result.
I added as a hyperlink to a cell and when I try to click on the cell, I get the following error:
Unable to open
https://nttdata.atlassian.net/...
Cannot download the information you requested
I thought it may be possible due to the length of the link (396 characters) that has more than 255 characters (see this question), then I created a shortened URL via Bitly, but I get the same error. If I copy and paste the URL directly in Chrome, I get the file downloaded using the original URL or the equivalent Bitly URL.
I also tried to access the hyperlink via VBA script too:
Range("G11").Select
Selection.Hyperlinks(1).Follow NewWindow:=False, AddHistory:=True
But I get the same error.
I have another similar URL created by JIRA that works well as a hyperlink:
https://nttdata.atlassian.net/sr/jira.issueviews:searchrequest-csv-current-fields/39627/SearchRequest-39627.csv?tempMax=1000
One of the differences of this URL is that instead of passing the parameters to the query (JiraQuery) it invokes a filter (saved query) under ID: 39627.
Any suggestion about what is going on here?, for sure there is something in the URL syntax that Excel does not like it, even the navigator accepts it.

Uploading an Excel spreadsheet to Google Sheets

I've been hitting my head on a brick wall with the following lovely conundrum:
The point is to get data from Excel to Google Sheets without uploading files, but going through the URLs. The following handily explain how all that business transpires:
https://www.youtube.com/watch?v=mX2_XNYPGiI
http://ramblings.mcpher.com/Home/excelquirks/exceldocsintegration/excelsheetsv4
I've tried to adapt the following code for the VBA side of things, common to both examples:
Option Explicit
Sub GetDataFromGoogle()
'link to tutorial: https://www.youtube.com/watch?v=mX2_XNYPGiI
Dim link As String
link = "https://docs.google.com/spreadsheets/d/e/2PACX-1vSes7Jb06JRy8KSFyNlpUSzNQxSB_HZay4S8AB2IqzpZP0QdwGO5PFSS-6uzd8v_GsjlkXM31pby2jE/pubhtml"
Sheet4.QueryTables(1).Connection = "URL;" & link
Sheet4.QueryTables(1).Refresh False
Sheet4.Columns(1).ColumnWidth = 10
End Sub
Sub PushDataToGoogle()
Dim link As String
link = "https://docs.google.com/forms/d/e/1FAIpQLSeDHEKJmRDynwOAS4g53T9AVMtpXQkWsRGbAzLpLI7rdsbiFA/formResponse?entry.1155739640=4&fvv=1&draftResponse=%5B%5B%5Bnull%2C1155739640%2C%5B%224%22%5D%0D%0A%2C0%5D%0D%0A%5D%0D%0A%2Cnull%2C%2276341394568976993%22%5D%0D"
'go to that link, refresh it and ensure that the first column isn't too narrow
sheets("Sheet4").QueryTables(1).Connection = "URL;" & link
sheets("Sheet4").QueryTables(1).Refresh True
sheets("Sheet4").Columns(1).ColumnWidth = 10
End Sub
On the Google Sheets side, I used a Form to create a spreadsheet that is both the data source for an Excel import and the destination for the export of data. Replcaing POST and GET in the HTML of the form page is the way to get the destination URL. Subsequently, that URL can be either hardcoded or edited with variables to get various inputs for the "entry.######" part of the URL, and then they are passed on to the sheet in the next available line, which would suit my purposes.
I hit a snag(s) with the oAuth2 part of the operation. From the example on the Desktop Liberation site (second link above), credentials are created from Google and then inserted into a code that authenticates the connection before transmitting the data. As such:
Private Function sheetsOnceOff()
getGoogled "sheets", , _
"1023445954023-hq8gkdcmo9sue822d23gy9ak5hmun27.apps.googleusercontent.com", _
"dX7ABCDEGFBETFWtvX5ShmDfrgrQ"
End Function
If that isn't done, the prior lines of code will just return the main Google login page. I've made the credentials, determined the destination key for the spreadsheet, but I get an error in the getGoogled routine that says:
Runtime-error: '-2147024809 (80070057)': The parameter is incorrect."
parameter values are as follows:
- scope = 'sheets', as it should be
- replacement package = ""
- clientID is OK
- clientSecret is OK
- complain = true
- cloneFromScope = ""
- apikey =""
I'm thinking the replacement package should not be empty if complain is true, but I feel that I'm out of my depth here. At least the logic of what needs to happen makes sense to me, and I've managed to get the transfer from Google Sheets to work fine, but I'm just not sure how to handle the oAuth2 authentication matter.
Thank you in advance.
The following is by no means a complete solution, but it is a rudimentary start. The condition on the following is to be logged into gmail, and it will move one piece of data into Google sheets with its timestamp. It works by direclty opening the page that appears after a user clicks Submit on the form, thus imitating a submission. Link2 opens the spreadsheet where the response is passed.
The downside is that it requires the user to be logged into gmail already and will open a new tab each time a variable is passed, so avoid modifying it with arrays or loops. However, I will try putting together a prior vba gmail project with this to see if can work. More will be forthcoming, but for a hacked together band-aid solution, this will do if someone needs it.
Credits and info here:
[https://stackoverflow.com/questions/3166265/open-an-html-page-in-default-browser-with-vba
https://stackoverflow.com/questions/5915325/open-google-chrome-from-vba-excel
Sub PushDataToGoogle()
Dim chromePath As String
chromePath = """C:\Program Files\Google\Chrome\Application\chrome.exe"""
Dim link As String, link2 As String
link = "https://docs.google.com/forms/d/e/1FAIpQLSeDHEKJmRDynwOAS4gtpXQkWsRGbAzLpLI7rdsbiFA/formResponse?entry.1155739640=4&fvv=1&draftResponse=%5B%5B%5Bnull%2C11557396%224%22%5D%0D%0A%2C0%5D%0D%0A%5D%0D%0A%2Cnull%2C%227634134997568976993%22%5D%0D"
link2 = "https://docs.google.com/spreadsheets/d/1W8A3UuFQTeEwk6-hqERvuIMT_HInySZTNBOIs/edit#gid=11262360"
Shell (chromePath & link)
ThisWorkbook.FollowHyperlink link2
End Sub
Turns out, the solution is considerably simpler, thanks to the Selenium Basic library, available here, with a lot of useful info about how it works:
https://codingislove.com/browser-automation-in-excel-selenium/
A note for your attention: this download needs Selenium GoogleChrome driver version 2.33, the current latest version, to resolve an error with Chrome starting up properly - at least in my case, I need Chrome and not IE working.
In any case, Selenium is a god-send for those in a similar situation. When you download and install Selenium, go into Tools --> References in the VB Editor, and enable the Selenium Type Library.
The following code will do the job:
Option Explicit
Dim myHTML_Element As IHTMLElement
Dim Driver As New WebDriver
Sub seleniumtutorial()
Dim pword As String
Dim link As String, link2 As String
pword = ThisWorkbook.sheets("Sheet1").Range("D10")
Driver.Start "chrome", "https://gmail.com"
Driver.Get ("https://gmail.com")
Driver.FindElementById("identifierId").SendKeys "user#company.com"
Driver.FindElementById("identifierNext").Click
'Driver.Get ("https://sso.diversey.com/nidp/saml2/sso?id=DIVAuthContract30&sid=0&option=credential&sid=0")
Driver.FindElementById("uname").SendKeys "Username"
Driver.FindElementById("pass").SendKeys pword
Driver.FindElementByName("loginButton2").Click
link = "https://docs.google.com/forms/d/e/1FAIpQLSeDHEKJmRDyMt7rdsbiFA/formResponse?entry.1155739640=7&fvv=1&draftR=%5B%5B%5Bnull%2C115B%224%22%5D%0D%0A%2C0%5D%%0A%5D%0D%0A%2Cnull%2C%227634134997568976993%22%5D%0D"
link2 = "https://docs.google.com/spreadsheets/d/1W8A3UuyeEwk6-hqERvuIMT_HInySBOIs/edit#gid=1126962360"
Driver.Get (link)
Driver.Get (link2)
End Sub
link and link2 are, respectively, the page that confirms a response has been submitted and link2 is the link to the spreadsheet that has the list of responses. You can divide this routine into two subs - one logs in the user, and the other creates an array of the items to be fed to google, at which points it just refreshes the same page with the new values, as it cycles through the loop or array.
One more link:
Selenium VBA - exit sub without close browser window
Making the variables public ensures that the browser window doesn't close at the end of the session, or you can declare them inside the first sub if you want it to close. As for credentials, you can either hardcode them or feed them from the spreadsheet, but that's a technicality. Beyond that, it seems like a pretty straightforward routine and it does the job really well.
The syntax of the Selenium library is decidedly more modern than VBA and I'd say quite a bit more powerful

notes url (notes://) sometimes does not create icon on workspace

I'm maintaining an application which sends out E-Mails with a notes url link like this:
noteshref = "notes://" & serverName.Common & "/" & docToLink.Parentdatabase.Replicaid & "/" & viewUNID & "/" & docToLink.Universalid
the viewUNID is calculated thusly:
Dim viewUNID As String
Set nc = db.Createnotecollection(False)
nc.Selectviews=True
nc.Selectionformula={#isMember("Vtousdocuments";#explode($Title;"|"))}
nc.Buildcollection
If nc.Count > 0 Then
viewID = nc.Getfirstnoteid
Dim note As NotesDocument
Set note = db.Getdocumentbyid(viewID)
viewUNID=note.Universalid
Delete note
Else
viewUNID="0"
End If
Delete nc
I've looked at the documentation for the NotesURL:
https://www-10.lotus.com/ldd/dominowiki.nsf/dx/notes-urls
I've seen demonstrations via a remote session when the database icon on the workspace is not created when opening the link. The Document gets opened, but no bananas on the 'create a Workspace icon on the database' behaviour.
I haven't been able to reproduce this on my machine, and I've also noted that, contrary to the documentation, the server 'hint' is not considered - one of the possible replicas is pulled out of thin air and recreated on the workspace.
Am I missing anything? Are there perhaps some combinations of the notesurl that do not create icons on the workspace (i.e. a naming convention for the server)? Or could it be something more obscure, like corrupted desktop.ndks?
I have used this URL format in few places and it has always worked and it opens the right server. One thing I do differently is use /0/ instead of the view UNID "/" & viewUNID & "/". This would directly open the document if its present in the db and its also faster.
But your solution also should work, if the issue is specific for few users you should delete the cache/desktop and try.

livecode and mergext dropbox sync

i am using mergext dropboxsync to synchronise my data from the ipad.
my question is.
how we get the file from the special folder specialfolderpath
and how we check if the file exist into the dropbox.
i am no using fields for folder or the files i want the procedure to be hidden from the user
to get my folder and path i use the simple bellow code.
put specialfolderpath("documents") & "/myfile.sqlite" into myPath
and here is the code from the button i use
on mouseUp
goToParent --<command
repeat for each line tempitem in fld "sFolders" --<hide field
add 1 to t
if tempitem ="hairaid-backup" then
put 1 into fExist
end if
end repeat
--!! if folder exist
if fExist is a number then
else
try
mergDropboxCreateFolder (hairaid &"-"&backup)
catch e
answer e
end try
end if
end mouseUp
I would not really recommend synchronising a sqlite database over dropbox. You are likely to have better results creating a tree for files for dropbox to sync as one large file is likely to end up with conflicted versions.
However, answering your question in the general sense you would need to do something like this:
put url ("binfile:"&myPath) into myData
mergDropboxWriteFile relativePath,myData
Then to get the data you:
put merDropboxGetFile(relativePath) into myData

Resources