Excel VBA - passing username & password to Web Query connection - excel

We have a web query on an Excel worksheet that goes to MoneyFacts (Moneyfacts website) for the latest Bond & ISA savings rates.
The rates page requires a login by username and password before the rates page is shown (as it's a subscription site).
Through trial and error and looking at the soruce of the login page, I was able to determin that I need to add these symbols to the connection:
User Name: ctl00$body$txtUsername
Password: ctl00$body$txtPassword
so I changed thec onnection property of the datatable as below:
sheets("ISA 3Yr").range("A12").QueryTable.Connection="URL;http://analyser.moneyfacts.co.uk/savings/forms/frmDashboard.aspx?symbol=[""body_txtUsername""]”&symbol=[""body_txtPassword""]”&did=37&module=2&tocfilter=15&view=2&rerun=92680f6c-9fcc-4585-9b2a-aaf9b281cf88"
Now, when we click refresh All on the ribbon the first time, the dialogs are shown so we can enter the username and password. Each time we chose entered the data and the web query refreshed.
But the next time, without asking for the login, it fails.
How can we pass parameters to web queries properly ?

Either you pass parameters in the query string portion of the web url, so in your example you have did=37&module=2&tocfilter=15&view=2& which is a series of key value pairs which gives
did=37
module=2
tocfilter=15
view=2
or they are posted in the HTTP header. You'll need an HTTP sniffer tool to investigate further. I used Fiddler at http://www.telerik.com/fiddler and it is quite good.

Related

Web query connection does not create table in excel

I have the below external link
https://creator.zohopublic.com/inovadms/inova-dms/view-embed/SPO_Export_Public/M1ZxYdK6k6TYpgZzX7BgHsSQEwSQ2aY27Fx7DHTfCtNgp3tvsUHTajsMxdekudO9hyR9MFe0SgbF8MBngY6UbW5YBmgjWuvk5WfQ/hotelrecid=1721972000009874027&type=1
I would like to connect it in Excel 2013 using web query (with the Power Query it works but I would like to implement it as web query from the Data tab).
In a new excel sheet I am doing the below
1) Open a blank sheet
2) Go to Data-> From Web
3) I add the link and click GO. It returns me the below. I am not sure if this error is the reason of my problem
4) By clicking 'Yes' I have the below (everything fine until now)
But when I click the import button (and select the first cell for this import) it returns an 'Open Page Builder' message. Why this happens?
I did not have this problem until last year and I do not understand what is the issue here.
Zoho Support told me that it is Microsoft issue. Can you please reproduce it and tell me why it does not show me the page in an excel table?
It should return be something like that (without the color format)
It works for me by following this method.
1) Open a blank sheet
2) Go to Data-> From Web
3) I add the link and click GO. It returns me the below
4). I choose Basic option and enter URL and click OK
5). I get the following screen
6). I Choose the second option that is Table. As per my experience data desired by us is contained in Tables.
7). I click Load button to get the data, which loads on web page correctly.
HTH
A). If you choose Advanced option in step 3 then we will get the following dialog box. In this box in upper part we can add a URL by its constituent parts. For example http://community.powerbi.com/t5/Desktop/How-to-setting-a-dynamic-URL-connection/td-p/57072
has been shown entered into its constituent parts in the snapshot shown below. Further details to set a dynamic URL connection can be referred in linked document.
B). In the lower part of the dialog box there is a drop down to select HTTP Request Header Parameters like
Accept Required. Set this to application/json.
Accept-Encoding Optional. Supported encodings are gzip and deflate.
Authorization Required. See authentication.
Connection Optional. It is recommended that Keep-Alive be enabled.
Content-Length Optional. It is recommended taht the request body length be specified when known.
etc....
Further details can referred Query Management HTTP Request
HTTP Request Header Parameters setting for various applications like
Enter data directly into Power BI Desktop
Connect to Excel in Power BI Desktop
Analysis Services multidimensional data in Power BI Desktop
Connect to CSV files in Power BI Desktop
Connect to a Google BigQuery database in Power BI Desktop
Connect to an Impala database in Power BI Desktop
Connect to an OData feed in Power BI Desktop
etc.. can be referred to power-bi/desktop-connect-excel
Edit:
Regarding OP's comment whether same Excel file can run on another PC, my opinion is it is not possible. When try to copy file to temporary storage for transfer, we get a warning that this file can not be copied to new location with its properties. Are you sure you want to copy without its properties. Please see this warning snap shot.
As such it seems that the same query may not work in a new location. New query has to be created for that location.

ServiceM8 API disabled?

myClientID & myURL are just placeholders for real values.
It seems that API access is inconsistent.
I was working on this last night, and it was working fine.
I would do a GET to the URL below:
https://www.servicem8.com/oauth/authorize?response_type=code&client_id=myclientID&scope=read_jobs&redirect_uri=http://myURL
This would pop-up an authorization screen where I would enter username & password
Then a pop-up would appear that with an “ALLOW” button
Once I clicked ALLOW it would forward to our website http://myURL
It also appended code=random-generated-temp-code&state= to the end of the URL
I then executed a POST command to generate the access_token from the temp-code
Today the form that asks the user to ALLOW does not pop-up, and so it does not generate the temp-api-code

Excel links to JIRA issues forcing re-authentication

Situation
Attempting to launch a JIRA issue hyperlink from Excel 2013 drives the user to a login page for JIRA which is unexpected as the user has an active login session.
Example link format --> https://<subdomain>.atlassian.net/browse/<proj-#>
Even if the user logs in the first time, checks the box for "Keep me logged in" the user still must repeat this the next time a JIRA link from Excel is selected.
The URL appends the parameter &permission-violation=true
Attempts to Debug
Copy the link to clipboard and paste directly in browser URL bar. This method does not generate the permission violation. User can go directly to issue without logging in again.
Attempt the link in a different Office 2013 application. Using the same link from a MS Outlook 2013 email does not generate the permission violation.
Browse the JIRA administration page for solutions. Could not find any such option to configure.
Tested with both Firefox and Chrome set as the default browser. Issue persists for each.
Any suggestions to fix this? The behavior is very frustrating to our end users.
The Problem
According to StackOverflow user myroslav, certain versions of Excel are first attempting to fetch the webpage using a Microsoft DLL that does not know about your browser's cookies (i.e. your login session). Here's an excerpt of his answer:
If session cookie protects website Hlink naturally is being redirected
to login page and having reached HTML page and not able to
"understand" it opens it in external browser. Note that it opens not
original URL (expected behavior) but the result of redirect, even if
it was 302 redirect.
His full answer can be read here.
The Solution
At this time, Microsoft has recommended that companies with single sign-on sites like Atlassian's should address the issue on their end. Such a fix is low on Atlassian's priority list. In the meantime, we are left to either accept Microsoft's solution - modify the registry as myroslav instructs and accept a loss of Excel functionality - or modify our URL to something that doesn't require single sign-on user validation.
The Workaround
I'm using Excel 2016 and Chrome. Taliesin's workaround, elsewhere on this page, did not work for me, but might work for some. Here's a next-best-thing workaround that did work:
HYPERLINK("https://<subdomain>.atlassian.net/issues/?jql=id%20in%20("&<cell>&")", "link")
Replace <subdomain> with your Atlassian subdomain, and <cell> with the cell containing your JIRA issue key.
This URL variant opens a search query for issues matching the given key. It doesn't take you directly to the issue, but it at least offers a convenient link to get where you want to go, which is at least better than entering your credentials on the login page again.
Try restarting the browser and login to JIRA by selecting keep me signed in
It seems to resolve the issue: https://www.redmine.org/boards/1/topics/14287?r=40540
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\"YOUR OFFICE VERSION"\Common\Internet]
"ForceShellExecute"=dword:00000001
Workaround
Ok. So I have discovered a workaround. Note this will correct the issue in an indirect way by leveraging JIRA's own link correction behavior. Essentially, you can bypass the security issue by providing JIRA with an incorrectly structured URL. JIRA will then fix the URL and redirect you to the correct page.
Here is the structure https://<subdomain>.atlassian.net/browse/<proj-#> + /
Note the last forward slash. This does not belong in the URL construction but when used will establish the redirect and thereby bypass the security violation.
If you already have your hyperlinks in a JIRA file you can easily update those in batch by using this simple VBA code subroutine.
Sub AppendJiraLinks()
Dim c As Range
Dim i As Integer
For Each c In Selection.Cells
If c.Hyperlinks.Count >= 1 Then
For i = 1 To c.Hyperlinks.Count
c.Hyperlinks(i).Address = c.Hyperlinks(i).Address & "/"
Next i
End If
Next c
End Sub
Note this code could be enhanced but works fine for my purposes.

Is it possible to show Edit Web Query window when the workbook is opened in excel

We have a url say:
http://www.example.com/myexcelbigdata/data.aspx which requires authentication. We want our users to be able to access this page via excel by using web query.
If I add the url as web query, it will be redirected to the login page (which is good). Then I type in username and password and login, /myexcelbigdata/data.aspx will be displayed again.
However, if I close and open the excel workbook again, the worksheet actually shows the login page (not the data page). Is there a way that excel can automatically show "edit web query" window every time the excel file is opened, so the users can provide username and password?
If possible, we don't want to use vba in excel book as customers will have to either use the excel we provide or knows how to type in the vba code.

Post Username & Password To Protected Folder/Site

I'm trying to post a username & password from an HTML form to a protected folder on a website? Is this possible? I thought I just pass in a syntax in the URL like the below but not having any success
http://username:password#theurlofthesite.co.uk
I'm still getting the alert pop up asking for the username and password? I need to be able to auto log the person in..
Hope someone can help? Thanks
If you login via a HTML form, then this won't work. This is only for HTTP authentication, which is something else completely different.
I don't think many (any?) browsers support being opened to post data. Which leaves you hoping that the site accepts GET based logins (and they should be shot if they do.).
The address part of the URL is parsed by your web server, so the code which handles the HTML form never sees it.
If you want to pass parameters to a form, you must use url?field=value&field2=value2. This only works with forms that use the GET action. For POST, you need a program to generate an encoded document and upload that.
In both cases, your user name and password are broadcasted as plain text on the Internet, so the account will be hacked within a few hours. To put it more clearly: There is no way to "protect" the data in this folder this way. This is like adding a door with four locks to your house and keep the keys on a nail in a post on the street next to the door.
I did exactly what I did in the question and it works on all browser except Safari on a Mac

Resources